Skip to content

Commit

Permalink
Enable querying entirely cold datasources (apache#16676)
Browse files Browse the repository at this point in the history
Add ability to query entirely cold datasources.
  • Loading branch information
findingrish authored Jul 15, 2024
1 parent 209f8a9 commit 6410453
Show file tree
Hide file tree
Showing 10 changed files with 853 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public interface CoordinatorClient
* Returns a new instance backed by a ServiceClient which follows the provided retryPolicy
*/
CoordinatorClient withRetryPolicy(ServiceRetryPolicy retryPolicy);

/**
* Retrieves list of datasources with used segments.
*/
ListenableFuture<Set<String>> fetchDataSourcesWithUsedSegments();
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,17 @@ public CoordinatorClientImpl withRetryPolicy(ServiceRetryPolicy retryPolicy)
{
return new CoordinatorClientImpl(client.withRetryPolicy(retryPolicy), jsonMapper);
}

@Override
public ListenableFuture<Set<String>> fetchDataSourcesWithUsedSegments()
{
final String path = "/druid/coordinator/v1/metadata/datasources";
return FutureUtils.transform(
client.asyncRequest(
new RequestBuilder(HttpMethod.GET, path),
new BytesFullResponseHandler()
),
holder -> JacksonUtils.readValue(jsonMapper, holder.getContent(), new TypeReference<Set<String>>() {})
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public abstract class AbstractSegmentMetadataCache<T extends DataSourceInformati
* Map of datasource and generic object extending DataSourceInformation.
* This structure can be accessed by {@link #cacheExec} and {@link #callbackExec} threads.
*/
protected final ConcurrentMap<String, T> tables = new ConcurrentHashMap<>();
protected final ConcurrentHashMap<String, T> tables = new ConcurrentHashMap<>();

/**
* This lock coordinates the access from multiple threads to those variables guarded by this lock.
Expand Down Expand Up @@ -269,9 +269,10 @@ protected void cacheExecLoop()
final boolean wasRecentFailure = DateTimes.utc(lastFailure)
.plus(config.getMetadataRefreshPeriod())
.isAfterNow();

if (isServerViewInitialized &&
!wasRecentFailure &&
(!segmentsNeedingRefresh.isEmpty() || !dataSourcesNeedingRebuild.isEmpty()) &&
shouldRefresh() &&
(refreshImmediately || nextRefresh < System.currentTimeMillis())) {
// We need to do a refresh. Break out of the waiting loop.
break;
Expand Down Expand Up @@ -334,6 +335,7 @@ protected void cacheExecLoop()
}
}


/**
* Lifecycle start method.
*/
Expand Down Expand Up @@ -361,6 +363,15 @@ public void refreshWaitCondition() throws InterruptedException
// noop
}

/**
* Refresh is executed only when there are segments or datasources needing refresh.
*/
@SuppressWarnings("GuardedBy")
protected boolean shouldRefresh()
{
return (!segmentsNeedingRefresh.isEmpty() || !dataSourcesNeedingRebuild.isEmpty());
}

public void awaitInitialization() throws InterruptedException
{
initialized.await();
Expand All @@ -373,6 +384,7 @@ public void awaitInitialization() throws InterruptedException
*
* @return schema information for the given datasource
*/
@Nullable
public T getDatasource(String name)
{
return tables.get(name);
Expand Down
Loading

0 comments on commit 6410453

Please sign in to comment.