@@ -16,23 +16,18 @@ use std::any::Any;
16
16
use std:: convert:: TryFrom ;
17
17
use std:: sync:: Arc ;
18
18
19
- use common_cache:: Cache ;
20
19
use common_catalog:: catalog:: StorageDescription ;
21
20
use common_catalog:: table_context:: TableContext ;
22
21
use common_catalog:: table_mutator:: TableMutator ;
23
22
use common_datablocks:: DataBlock ;
24
23
use common_exception:: ErrorCode ;
25
24
use common_exception:: Result ;
26
- use common_fuse_meta:: caches:: CacheManager ;
27
25
use common_fuse_meta:: meta:: ClusterKey ;
28
26
use common_fuse_meta:: meta:: Statistics as FuseStatistics ;
29
27
use common_fuse_meta:: meta:: TableSnapshot ;
30
28
use common_fuse_meta:: meta:: Versioned ;
31
29
use common_legacy_parser:: ExpressionParser ;
32
30
use common_meta_app:: schema:: TableInfo ;
33
- use common_meta_app:: schema:: TableMeta ;
34
- use common_meta_app:: schema:: UpdateTableMetaReq ;
35
- use common_meta_types:: MatchSeq ;
36
31
use common_planners:: DeletePlan ;
37
32
use common_planners:: Expression ;
38
33
use common_planners:: Extras ;
@@ -43,7 +38,6 @@ use common_planners::TruncateTablePlan;
43
38
use common_storages_util:: storage_context:: StorageContext ;
44
39
use uuid:: Uuid ;
45
40
46
- use crate :: io:: write_meta;
47
41
use crate :: io:: BlockCompactor ;
48
42
use crate :: io:: MetaReaders ;
49
43
use crate :: io:: TableMetaLocationGenerator ;
@@ -174,52 +168,52 @@ impl FuseTable {
174
168
}
175
169
}
176
170
177
- pub async fn update_table_meta (
178
- & self ,
179
- ctx : & dyn TableContext ,
180
- catalog_name : & str ,
181
- snapshot : & TableSnapshot ,
182
- meta : & mut TableMeta ,
183
- ) -> Result < ( ) > {
184
- let uuid = snapshot. snapshot_id ;
185
- let snapshot_loc = self
186
- . meta_location_generator ( )
187
- . snapshot_location_from_uuid ( & uuid, TableSnapshot :: VERSION ) ?;
188
- let operator = ctx. get_storage_operator ( ) ?;
189
- write_meta ( & operator, & snapshot_loc, snapshot) . await ?;
190
-
191
- // set new snapshot location
192
- meta. options
193
- . insert ( OPT_KEY_SNAPSHOT_LOCATION . to_owned ( ) , snapshot_loc. clone ( ) ) ;
194
- // remove legacy options
195
- meta. options . remove ( OPT_KEY_LEGACY_SNAPSHOT_LOC ) ;
196
-
197
- let table_id = self . table_info . ident . table_id ;
198
- let table_version = self . table_info . ident . seq ;
199
- let req = UpdateTableMetaReq {
200
- table_id,
201
- seq : MatchSeq :: Exact ( table_version) ,
202
- new_table_meta : meta. clone ( ) ,
203
- } ;
204
-
205
- let catalog = ctx. get_catalog ( catalog_name) ?;
206
- let result = catalog. update_table_meta ( req) . await ;
207
- match result {
208
- Ok ( _) => {
209
- if let Some ( snapshot_cache) = CacheManager :: instance ( ) . get_table_snapshot_cache ( ) {
210
- let cache = & mut snapshot_cache. write ( ) . await ;
211
- cache. put ( snapshot_loc, Arc :: new ( snapshot. clone ( ) ) ) ;
212
- }
213
- Ok ( ( ) )
214
- }
215
- Err ( e) => {
216
- // commit snapshot to meta server failed, try to delete it.
217
- // "major GC" will collect this, if deletion failure (even after DAL retried)
218
- let _ = operator. object ( & snapshot_loc) . delete ( ) . await ;
219
- Err ( e)
220
- }
221
- }
222
- }
171
+ // pub async fn update_table_meta(
172
+ // &self,
173
+ // ctx: &dyn TableContext,
174
+ // catalog_name: &str,
175
+ // snapshot: &TableSnapshot,
176
+ // meta: &mut TableMeta,
177
+ // ) -> Result<()> {
178
+ // let uuid = snapshot.snapshot_id;
179
+ // let snapshot_loc = self
180
+ // .meta_location_generator()
181
+ // .snapshot_location_from_uuid(&uuid, TableSnapshot::VERSION)?;
182
+ // let operator = ctx.get_storage_operator()?;
183
+ // write_meta(&operator, &snapshot_loc, snapshot).await?;
184
+ //
185
+ // // set new snapshot location
186
+ // meta.options
187
+ // .insert(OPT_KEY_SNAPSHOT_LOCATION.to_owned(), snapshot_loc.clone());
188
+ // // remove legacy options
189
+ // meta.options.remove(OPT_KEY_LEGACY_SNAPSHOT_LOC);
190
+ //
191
+ // let table_id = self.table_info.ident.table_id;
192
+ // let table_version = self.table_info.ident.seq;
193
+ // let req = UpdateTableMetaReq {
194
+ // table_id,
195
+ // seq: MatchSeq::Exact(table_version),
196
+ // new_table_meta: meta.clone(),
197
+ // };
198
+ //
199
+ // let catalog = ctx.get_catalog(catalog_name)?;
200
+ // let result = catalog.update_table_meta(req).await;
201
+ // match result {
202
+ // Ok(_) => {
203
+ // if let Some(snapshot_cache) = CacheManager::instance().get_table_snapshot_cache() {
204
+ // let cache = &mut snapshot_cache.write().await;
205
+ // cache.put(snapshot_loc, Arc::new(snapshot.clone()));
206
+ // }
207
+ // Ok(())
208
+ // }
209
+ // Err(e) => {
210
+ // // commit snapshot to meta server failed, try to delete it.
211
+ // // "major GC" will collect this, if deletion failure (even after DAL retried)
212
+ // let _ = operator.object(&snapshot_loc).delete().await;
213
+ // Err(e)
214
+ // }
215
+ // }
216
+ // }
223
217
224
218
pub fn transient ( & self ) -> bool {
225
219
self . table_info . meta . options . contains_key ( "TRANSIENT" )
@@ -287,8 +281,9 @@ impl Table for FuseTable {
287
281
( FuseStatistics :: default ( ) , vec ! [ ] )
288
282
} ;
289
283
284
+ let new_snapshot_id = Uuid :: new_v4 ( ) ;
290
285
let new_snapshot = TableSnapshot :: new (
291
- Uuid :: new_v4 ( ) ,
286
+ new_snapshot_id ,
292
287
& prev_timestamp,
293
288
prev_snapshot_id,
294
289
schema,
@@ -297,13 +292,21 @@ impl Table for FuseTable {
297
292
cluster_key_meta,
298
293
) ;
299
294
300
- self . update_table_meta (
295
+ // write down the new snapshot
296
+ let snapshot_loc = self . meta_location_generator . snapshot_location_from_uuid (
297
+ & new_snapshot. snapshot_id ,
298
+ new_snapshot. format_version ( ) ,
299
+ ) ?;
300
+
301
+ FuseTable :: commit_to_meta_server (
301
302
ctx. as_ref ( ) ,
302
303
catalog_name,
303
- & new_snapshot,
304
- & mut new_table_meta,
304
+ & self . table_info ,
305
+ snapshot_loc,
306
+ new_snapshot,
305
307
)
306
- . await
308
+ . await ?;
309
+ Ok ( ( ) )
307
310
}
308
311
309
312
async fn drop_table_cluster_keys (
@@ -331,8 +334,9 @@ impl Table for FuseTable {
331
334
( FuseStatistics :: default ( ) , vec ! [ ] )
332
335
} ;
333
336
337
+ let new_snapshot_id = Uuid :: new_v4 ( ) ;
334
338
let new_snapshot = TableSnapshot :: new (
335
- Uuid :: new_v4 ( ) ,
339
+ new_snapshot_id ,
336
340
& prev_timestamp,
337
341
prev_snapshot_id,
338
342
schema,
@@ -341,11 +345,18 @@ impl Table for FuseTable {
341
345
None ,
342
346
) ;
343
347
344
- self . update_table_meta (
348
+ // write down the new snapshot
349
+ let snapshot_loc = self . meta_location_generator . snapshot_location_from_uuid (
350
+ & new_snapshot. snapshot_id ,
351
+ new_snapshot. format_version ( ) ,
352
+ ) ?;
353
+
354
+ FuseTable :: commit_to_meta_server (
345
355
ctx. as_ref ( ) ,
346
356
catalog_name,
347
- & new_snapshot,
348
- & mut new_table_meta,
357
+ & self . table_info ,
358
+ snapshot_loc,
359
+ new_snapshot,
349
360
)
350
361
. await
351
362
}
0 commit comments