1818package org .apache .fluss .server .coordinator ;
1919
2020import org .apache .fluss .annotation .VisibleForTesting ;
21+ import org .apache .fluss .fs .FsPath ;
22+ import org .apache .fluss .metadata .PhysicalTablePath ;
2123import org .apache .fluss .metadata .TableBucket ;
22- import org .apache .fluss .metadata .TablePath ;
2324import org .apache .fluss .metrics .MetricNames ;
2425import org .apache .fluss .metrics .groups .MetricGroup ;
2526import org .apache .fluss .server .kv .snapshot .CompletedSnapshot ;
3031import org .apache .fluss .server .kv .snapshot .ZooKeeperCompletedSnapshotHandleStore ;
3132import org .apache .fluss .server .metrics .group .CoordinatorMetricGroup ;
3233import org .apache .fluss .server .zk .ZooKeeperClient ;
34+ import org .apache .fluss .utils .FlussPaths ;
3335import org .apache .fluss .utils .MapUtils ;
3436
3537import org .slf4j .Logger ;
@@ -66,17 +68,21 @@ public class CompletedSnapshotStoreManager {
6668 makeZookeeperCompletedSnapshotHandleStore ;
6769 private final CoordinatorMetricGroup coordinatorMetricGroup ;
6870
71+ private final FsPath remoteKvDir ;
72+
6973 public CompletedSnapshotStoreManager (
7074 int maxNumberOfSnapshotsToRetain ,
7175 Executor ioExecutor ,
7276 ZooKeeperClient zooKeeperClient ,
73- CoordinatorMetricGroup coordinatorMetricGroup ) {
77+ CoordinatorMetricGroup coordinatorMetricGroup ,
78+ FsPath remoteKvDir ) {
7479 this (
7580 maxNumberOfSnapshotsToRetain ,
7681 ioExecutor ,
7782 zooKeeperClient ,
7883 ZooKeeperCompletedSnapshotHandleStore ::new ,
79- coordinatorMetricGroup );
84+ coordinatorMetricGroup ,
85+ remoteKvDir );
8086 }
8187
8288 @ VisibleForTesting
@@ -86,7 +92,8 @@ public CompletedSnapshotStoreManager(
8692 ZooKeeperClient zooKeeperClient ,
8793 Function <ZooKeeperClient , CompletedSnapshotHandleStore >
8894 makeZookeeperCompletedSnapshotHandleStore ,
89- CoordinatorMetricGroup coordinatorMetricGroup ) {
95+ CoordinatorMetricGroup coordinatorMetricGroup ,
96+ FsPath remoteKvDir ) {
9097 checkArgument (
9198 maxNumberOfSnapshotsToRetain > 0 , "maxNumberOfSnapshotsToRetain must be positive" );
9299 this .maxNumberOfSnapshotsToRetain = maxNumberOfSnapshotsToRetain ;
@@ -95,6 +102,7 @@ public CompletedSnapshotStoreManager(
95102 this .ioExecutor = ioExecutor ;
96103 this .makeZookeeperCompletedSnapshotHandleStore = makeZookeeperCompletedSnapshotHandleStore ;
97104 this .coordinatorMetricGroup = coordinatorMetricGroup ;
105+ this .remoteKvDir = remoteKvDir ;
98106
99107 registerMetrics ();
100108 }
@@ -121,15 +129,15 @@ private long getAllSnapshotSize(TableBucket tableBucket) {
121129 }
122130
123131 public CompletedSnapshotStore getOrCreateCompletedSnapshotStore (
124- TablePath tablePath , TableBucket tableBucket ) {
132+ PhysicalTablePath tablePath , TableBucket tableBucket ) {
125133 return bucketCompletedSnapshotStores .computeIfAbsent (
126134 tableBucket ,
127135 (bucket ) -> {
128136 try {
129137 LOG .info ("Creating snapshot store for table bucket {}." , bucket );
130138 long start = System .currentTimeMillis ();
131139 CompletedSnapshotStore snapshotStore =
132- createCompletedSnapshotStore (tableBucket , ioExecutor );
140+ createCompletedSnapshotStore (tablePath , tableBucket , ioExecutor );
133141 long end = System .currentTimeMillis ();
134142 LOG .info (
135143 "Created snapshot store for table bucket {} in {} ms." ,
@@ -138,7 +146,7 @@ public CompletedSnapshotStore getOrCreateCompletedSnapshotStore(
138146
139147 MetricGroup bucketMetricGroup =
140148 coordinatorMetricGroup .getTableBucketMetricGroup (
141- tablePath , tableBucket );
149+ tablePath . getTablePath () , tableBucket );
142150 if (bucketMetricGroup != null ) {
143151 LOG .info ("Add bucketMetricGroup for tableBucket {}." , bucket );
144152 bucketMetricGroup .gauge (
@@ -168,7 +176,8 @@ public void removeCompletedSnapshotStoreByTableBuckets(Set<TableBucket> tableBuc
168176 }
169177
170178 private CompletedSnapshotStore createCompletedSnapshotStore (
171- TableBucket tableBucket , Executor ioExecutor ) throws Exception {
179+ PhysicalTablePath tablePath , TableBucket tableBucket , Executor ioExecutor )
180+ throws Exception {
172181 final CompletedSnapshotHandleStore completedSnapshotHandleStore =
173182 this .makeZookeeperCompletedSnapshotHandleStore .apply (zooKeeperClient );
174183
@@ -179,14 +188,18 @@ private CompletedSnapshotStore createCompletedSnapshotStore(
179188 final int numberOfInitialSnapshots = initialSnapshots .size ();
180189
181190 LOG .info (
182- "Found {} snapshots in {}." ,
191+ "Found {} snapshots in {} of table bucket {} ." ,
183192 numberOfInitialSnapshots ,
184- completedSnapshotHandleStore .getClass ().getSimpleName ());
193+ completedSnapshotHandleStore .getClass ().getSimpleName (),
194+ tableBucket );
185195
186196 final List <CompletedSnapshot > retrievedSnapshots =
187197 new ArrayList <>(numberOfInitialSnapshots );
188198
189- LOG .info ("Trying to fetch {} snapshots from storage." , numberOfInitialSnapshots );
199+ LOG .info (
200+ "Trying to fetch {} snapshots from storage of table bucket {}." ,
201+ numberOfInitialSnapshots ,
202+ tableBucket );
190203
191204 for (CompletedSnapshotHandle snapshotStateHandle : initialSnapshots ) {
192205 try {
@@ -205,28 +218,36 @@ private CompletedSnapshotStore createCompletedSnapshotStore(
205218 tableBucket , snapshotStateHandle .getSnapshotId ());
206219 } catch (Exception t ) {
207220 LOG .error (
208- "Failed to remove snapshotStateHandle {}." , snapshotStateHandle , t );
221+ "Failed to remove snapshotStateHandle {} of table bucket {}." ,
222+ snapshotStateHandle ,
223+ tableBucket ,
224+ t );
209225 throw t ;
210226 }
211227 } else {
212228 LOG .error (
213- "Failed to retrieveCompleteSnapshot for snapshotStateHandle {}." ,
229+ "Failed to retrieveCompleteSnapshot for snapshotStateHandle {} of table bucket {} ." ,
214230 snapshotStateHandle ,
231+ tableBucket ,
215232 e );
216233 throw e ;
217234 }
218235 }
219236 }
220237
238+ FsPath remoteKvTabletDir =
239+ FlussPaths .remoteKvTabletDir (remoteKvDir , tablePath , tableBucket );
221240 // register all the files to shared kv file registry
222- SharedKvFileRegistry sharedKvFileRegistry = new SharedKvFileRegistry (ioExecutor );
241+ SharedKvFileRegistry sharedKvFileRegistry =
242+ new SharedKvFileRegistry (remoteKvTabletDir , ioExecutor );
223243 for (CompletedSnapshot completedSnapshot : retrievedSnapshots ) {
224244 try {
225245 sharedKvFileRegistry .registerAllAfterRestored (completedSnapshot );
226246 } catch (Exception e ) {
227247 LOG .error (
228- "Failed to registerAllAfterRestored for completedSnapshot {}." ,
248+ "Failed to registerAllAfterRestored for completedSnapshot {} of table bucket {} ." ,
229249 completedSnapshot ,
250+ tableBucket ,
230251 e );
231252 throw e ;
232253 }
@@ -237,7 +258,8 @@ private CompletedSnapshotStore createCompletedSnapshotStore(
237258 sharedKvFileRegistry ,
238259 retrievedSnapshots ,
239260 completedSnapshotHandleStore ,
240- ioExecutor );
261+ ioExecutor ,
262+ remoteKvTabletDir );
241263 }
242264
243265 @ VisibleForTesting
0 commit comments