|
50 | 50 | /** Implementation of {@link LakeCommitter} for Lance. */ |
51 | 51 | public class LanceLakeCommitter implements LakeCommitter<LanceWriteResult, LanceCommittable> { |
52 | 52 | private final LanceConfig config; |
53 | | - private static String commitUser = "commit-user"; |
| 53 | + private static final String committerName = "commit-user"; |
54 | 54 | private final RootAllocator allocator = new RootAllocator(); |
55 | 55 | private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
56 | 56 |
|
@@ -78,7 +78,7 @@ public LanceCommittable toCommittable(List<LanceWriteResult> lanceWriteResults) |
78 | 78 | public long commit(LanceCommittable committable, Map<String, String> snapshotProperties) |
79 | 79 | throws IOException { |
80 | 80 | Map<String, String> properties = new HashMap<>(snapshotProperties); |
81 | | - properties.put(commitUser, FLUSS_LAKE_TIERING_COMMIT_USER); |
| 81 | + properties.put(committerName, FLUSS_LAKE_TIERING_COMMIT_USER); |
82 | 82 | return LanceDatasetAdapter.commitAppend(config, committable.committable(), properties); |
83 | 83 | } |
84 | 84 |
|
@@ -133,22 +133,21 @@ public CommittedLakeSnapshot getMissingLakeSnapshot(@Nullable Long latestLakeSna |
133 | 133 | @Nullable |
134 | 134 | private Transaction getCommittedLatestSnapshotOfLake(String commitUser) { |
135 | 135 | Transaction latestFlussSnapshot = null; |
136 | | - |
137 | 136 | ReadOptions.Builder builder = new ReadOptions.Builder(); |
138 | 137 | builder.setStorageOptions(LanceConfig.genStorageOptions(config)); |
139 | 138 | try (Dataset dataset = Dataset.open(allocator, config.getDatasetUri(), builder.build())) { |
140 | | - for (Version version : dataset.listVersions()) { |
| 139 | + List<Version> versions = dataset.listVersions(); |
| 140 | + for (int i = versions.size() - 1; i >= 0; i--) { |
| 141 | + Version version = versions.get(i); |
141 | 142 | builder.setVersion((int) version.getId()); |
142 | | - try (Dataset datasetVersion = |
| 143 | + try (Dataset datasetRead = |
143 | 144 | Dataset.open(allocator, config.getDatasetUri(), builder.build())) { |
144 | | - Transaction transaction = datasetVersion.readTransaction().orElse(null); |
| 145 | + Transaction transaction = datasetRead.readTransaction().orElse(null); |
145 | 146 | if (transaction != null |
146 | 147 | && commitUser.equals( |
147 | | - transaction.transactionProperties().get(commitUser))) { |
148 | | - if (latestFlussSnapshot == null |
149 | | - || transaction.readVersion() > latestFlussSnapshot.readVersion()) { |
150 | | - latestFlussSnapshot = transaction; |
151 | | - } |
| 148 | + transaction.transactionProperties().get(committerName))) { |
| 149 | + latestFlussSnapshot = transaction; |
| 150 | + break; |
152 | 151 | } |
153 | 152 | } |
154 | 153 | } |
|
0 commit comments