morningman commented on code in PR #70830:
URL: https://github.com/apache/doris/pull/70830#discussion_r4663506014
##########
fe/fe-connector/fe-connector-lance/src/main/java/org/apache/doris/connector/lance/LanceCatalogClient.java:
##########
@@ -202,26 +258,48 @@ private <T> T readTable(String dbName, String tableName,
OptionalLong version, T
}, "load Lance table metadata for " + what);
}
- private static LanceTableMetadata readMetadata(Dataset dataset,
LanceTableAccess access) {
- List<LanceFragmentInfo> fragments = new ArrayList<>();
- for (Fragment fragment : dataset.getFragments()) {
- fragments.add(new
LanceFragmentInfo(Integer.toUnsignedLong(fragment.getId()),
- fragment.metadata().getNumRows(),
fragment.metadata().getPhysicalRows()));
+ private static LanceTableMetadata readMetadata(Dataset dataset,
LanceTableAccess access,
+ LanceMetadataMetrics.Timer timer) {
+ Schema schema = timer.measure(Stage.SCHEMA, dataset::getSchema);
+ List<LanceFragmentInfo> fragments = timer.measure(Stage.FRAGMENTS, ()
-> {
+ List<LanceFragmentInfo> infos = new ArrayList<>();
+ for (Fragment fragment : dataset.getFragments()) {
+ infos.add(new
LanceFragmentInfo(Integer.toUnsignedLong(fragment.getId()),
+ fragment.metadata().getNumRows(),
fragment.metadata().getPhysicalRows()));
+ }
+ return infos;
+ });
+ return new LanceTableMetadata(access, dataset.version(), schema,
fragments);
+ }
+
+ private static long versionAtOrBefore(Dataset latest, long
timestampMillis, String requestedText,
+ String what) {
+ try {
+ return
LanceSnapshotResolver.versionAtOrBefore(latest.listVersions(), timestampMillis,
requestedText);
+ } catch (LanceSnapshotResolver.NoVersionAtOrBeforeException e) {
+ throw new UserFacingException("Lance table " + what + " has no
version at or before '"
+ + requestedText + "'");
+ } catch (LanceSnapshotResolver.HistoryRemovedException e) {
+ throw new UserFacingException("Lance cannot resolve FOR TIME AS OF
'" + requestedText
+ + "' on " + what + ": version " + e.getVersion()
+ + ", which may hold the state at that time, no longer
exists");
}
- return new LanceTableMetadata(access, dataset.version(),
dataset.getSchema(), fragments);
}
- private static Dataset openDataset(BufferAllocator readAllocator,
LanceTableAccess access,
- OptionalLong version) {
+ /**
+ * Opens the dataset with the generation's Session: its caches, not the
dataset, decide how much metadata is
+ * kept, and the next open of the same version reads it from them.
+ */
+ private static Dataset openDataset(Generation generation, BufferAllocator
readAllocator,
+ LanceTableAccess access, OptionalLong version,
LanceMetadataMetrics.Timer timer) {
ReadOptions.Builder options = new ReadOptions.Builder()
.setStorageOptions(access.getStorageOptions())
- .setIndexCacheSizeBytes(0)
- .setMetadataCacheSizeBytes(METADATA_CACHE_SIZE_BYTES);
+ .setSession(generation.session);
Review Comment:
Not changing what REFRESH TABLE / DATABASE do; b1213387c0b corrects the
comment and adds the test. The stale window is narrower than this says.
Manifests, schemas and fragment lists are cached by version plus the manifest's
e-tag, and opening the newest version always resolves a fresh location, so
after a same-URI rewrite a REFRESH TABLE reads them right (probed with the
bundled lance-core 12.0.0). Only a pinned version's index list can go stale,
and only with V1 manifest names (`_versions/<n>.manifest`): Lance keys it with
`e_tag.unwrap_or("")`, and a pinned V1 open has no e-tag. Keeping the Session
on REFRESH TABLE / DATABASE is 4.2's design (only REFRESH CATALOG rotates it),
the PR description names REFRESH CATALOG for a dataset replaced at the same
URI, and rotating on every REFRESH TABLE would drop the cached metadata of
every table in the catalog. The `invalidateDb` javadoc's "versions are
immutable" missed this case and now says so;
`LanceSharedSessionNativeTest.catalogRefr
eshReadsTheIndexesOfADatasetWrittenAgainAtTheSameUri` reads `[id_idx]` instead
of `[]` when REFRESH CATALOG drops only the access cache.
##########
fe/fe-connector/fe-connector-lance/src/main/java/org/apache/doris/connector/lance/LanceCatalogClient.java:
##########
@@ -148,40 +176,68 @@ LanceIndexMetadata loadIndexMetadata(String dbName,
String tableName, long versi
* the commit times the manifests record; see {@link
LanceSnapshotResolver#versionAtOrBefore}.
*/
LanceTableMetadata loadTableMetadataAtOrBefore(String dbName, String
tableName, long timestampMillis,
- String requestedText) {
+ String requestedText, LanceMetadataMetrics metrics) {
String what = dbName + "." + tableName;
- return readTable(dbName, tableName, OptionalLong.empty(), (access,
readAllocator) -> {
- long version;
- try (Dataset latest = openDataset(readAllocator, access,
OptionalLong.empty())) {
- try {
- version =
LanceSnapshotResolver.versionAtOrBefore(latest.listVersions(), timestampMillis,
- requestedText);
- } catch (LanceSnapshotResolver.NoVersionAtOrBeforeException e)
{
- throw new UserFacingException("Lance table " + what + "
has no version at or before '"
- + requestedText + "'");
- } catch (LanceSnapshotResolver.HistoryRemovedException e) {
- throw new UserFacingException("Lance cannot resolve FOR
TIME AS OF '" + requestedText
- + "' on " + what + ": version " + e.getVersion()
- + ", which may hold the state at that time, no
longer exists");
- }
- }
- LOG.debug("Resolved Lance FOR TIME AS OF '{}' to version {} from
manifest commit times",
- requestedText, version);
- try (Dataset dataset = openDataset(readAllocator, access,
OptionalLong.of(version))) {
- return readMetadata(dataset, access);
- }
- });
+ return readTable(dbName, tableName, OptionalLong.empty(), metrics,
+ (generation, access, readAllocator, timer) -> {
+ long version;
+ try (Dataset latest = openDataset(generation,
readAllocator, access, OptionalLong.empty(),
+ timer)) {
+ version = timer.measure(Stage.VERSION_RESOLVE,
+ () -> versionAtOrBefore(latest,
timestampMillis, requestedText, what));
+ }
+ LOG.debug("Resolved Lance FOR TIME AS OF '{}' to version
{} from manifest commit times",
+ requestedText, version);
+ try (Dataset dataset = openDataset(generation,
readAllocator, access, OptionalLong.of(version),
+ timer)) {
+ return readMetadata(dataset, access, timer);
+ }
+ });
+ }
+
+ /**
+ * REFRESH CATALOG: retires the current generation, so that the next call
opens a new namespace, allocator and
+ * Session. Opens nothing and waits for nothing: calls in flight finish on
the retired generation, and the
+ * last of them releases it.
+ */
+ void refresh() {
+ Generation idle = retireCurrent();
Review Comment:
Not changing this; b1213387c0b corrects the "two generations" wording in
`lance.conf.template` and `LanceConf`. The 192 MiB are capacities that fill on
demand, not allocations: a new Session with them reports `sizeBytes()` = 152. A
retired generation lives only while a call admitted before the refresh still
runs on it, and its last call releases it, so the retired generations alive at
once never outnumber the catalog's calls in flight; and since generations open
on the first call, a REFRESH CATALOG with no call since the previous one
retires nothing. 4.2 uses the same model and even builds a replacement on every
refresh. A bound would make a refresh or a new call wait for old calls to
drain, which 4.2 avoids by design (a refresh never waits for reads in flight),
and closing a retired Session early is unsafe under a running JNI call; the
12.0.0 Java `Session` cannot be shrunk while in use either.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]