1
1
package com .linkedin .davinci .repository ;
2
2
3
3
import static com .linkedin .venice .ConfigKeys .CLIENT_SYSTEM_STORE_REPOSITORY_REFRESH_INTERVAL_SECONDS ;
4
- import static com .linkedin .venice .system .store .MetaStoreWriter .KEY_STRING_SCHEMA_ID ;
5
- import static com .linkedin .venice .system .store .MetaStoreWriter .KEY_STRING_STORE_NAME ;
6
4
import static java .lang .Thread .currentThread ;
7
5
8
6
import com .linkedin .davinci .stats .NativeMetadataRepositoryStats ;
25
23
import com .linkedin .venice .schema .rmd .RmdSchemaEntry ;
26
24
import com .linkedin .venice .schema .writecompute .DerivedSchemaEntry ;
27
25
import com .linkedin .venice .service .ICProvider ;
28
- import com .linkedin .venice .system .store .MetaStoreDataType ;
29
- import com .linkedin .venice .systemstore .schemas .StoreClusterConfig ;
30
- import com .linkedin .venice .systemstore .schemas .StoreMetaKey ;
31
- import com .linkedin .venice .systemstore .schemas .StoreMetaValue ;
32
26
import com .linkedin .venice .utils .VeniceProperties ;
33
27
import com .linkedin .venice .utils .concurrent .VeniceConcurrentHashMap ;
34
28
import java .time .Clock ;
35
29
import java .util .ArrayList ;
36
30
import java .util .Collection ;
37
- import java .util .Collections ;
38
- import java .util .HashMap ;
39
31
import java .util .List ;
40
32
import java .util .Map ;
41
33
import java .util .Set ;
@@ -70,7 +62,7 @@ public abstract class NativeMetadataRepository
70
62
private final Map <String , StoreConfig > storeConfigMap = new VeniceConcurrentHashMap <>();
71
63
// Local cache for key/value schemas. SchemaData supports one key schema per store only, which may need to be changed
72
64
// for key schema evolvability.
73
- private final Map <String , SchemaData > schemaMap = new VeniceConcurrentHashMap <>();
65
+ protected final Map <String , SchemaData > schemaMap = new VeniceConcurrentHashMap <>();
74
66
private final ScheduledExecutorService scheduler = Executors .newScheduledThreadPool (1 );
75
67
private final Set <StoreDataChangedListener > listeners = new CopyOnWriteArraySet <>();
76
68
private final AtomicLong totalStoreReadQuota = new AtomicLong ();
@@ -128,8 +120,12 @@ public static NativeMetadataRepository getInstance(
128
120
LOGGER .info (
129
121
"Initializing {} with {}" ,
130
122
NativeMetadataRepository .class .getSimpleName (),
131
- ThinClientMetaStoreBasedRepository .class .getSimpleName ());
132
- return new ThinClientMetaStoreBasedRepository (clientConfig , backendConfig , icProvider );
123
+ RequestBasedMetaRepository .class .getSimpleName ());
124
+ if (clientConfig .isUseRequestBasedMetaRepository ()) {
125
+ return new RequestBasedMetaRepository (clientConfig , backendConfig );
126
+ } else {
127
+ return new ThinClientMetaStoreBasedRepository (clientConfig , backendConfig , icProvider );
128
+ }
133
129
}
134
130
135
131
@ Override
@@ -171,20 +167,14 @@ public boolean hasStore(String storeName) {
171
167
@ Override
172
168
public Store refreshOneStore (String storeName ) {
173
169
try {
174
- getAndSetStoreConfigFromSystemStore (storeName );
175
- StoreConfig storeConfig = storeConfigMap .get (storeName );
170
+ StoreConfig storeConfig = cacheStoreConfigFromRemote (storeName );
176
171
if (storeConfig == null ) {
177
172
throw new VeniceException ("StoreConfig is missing unexpectedly for store: " + storeName );
178
173
}
179
- Store newStore = getStoreFromSystemStore (storeName , storeConfig .getCluster ());
180
- // isDeleting check to detect deleted store is only supported by meta system store based implementation.
181
- if (newStore != null && !storeConfig .isDeleting ()) {
182
- putStore (newStore );
183
- getAndCacheSchemaDataFromSystemStore (storeName );
184
- nativeMetadataRepositoryStats .updateCacheTimestamp (storeName , clock .millis ());
185
- } else {
186
- removeStore (storeName );
187
- }
174
+ Store newStore = fetchStoreFromRemote (storeName , storeConfig .getCluster ());
175
+ putStore (newStore );
176
+ getAndCacheSchemaData (storeName );
177
+ nativeMetadataRepositoryStats .updateCacheTimestamp (storeName , clock .millis ());
188
178
return newStore ;
189
179
} catch (ServiceDiscoveryException | MissingKeyInStoreMetadataException e ) {
190
180
throw new VeniceNoStoreException (storeName , e );
@@ -393,74 +383,17 @@ public void clear() {
393
383
* Get the store cluster config from system store and update the local cache with it. Different implementation will
394
384
* get the data differently but should all populate the store cluster config map.
395
385
*/
396
- protected void getAndSetStoreConfigFromSystemStore (String storeName ) {
397
- storeConfigMap .put (storeName , getStoreConfigFromSystemStore (storeName ));
386
+ protected StoreConfig cacheStoreConfigFromRemote (String storeName ) {
387
+ StoreConfig storeConfig = fetchStoreConfigFromRemote (storeName );
388
+ storeConfigMap .put (storeName , storeConfig );
389
+ return storeConfig ;
398
390
}
399
391
400
- protected abstract StoreConfig getStoreConfigFromSystemStore (String storeName );
392
+ protected abstract StoreConfig fetchStoreConfigFromRemote (String storeName );
401
393
402
- protected abstract Store getStoreFromSystemStore (String storeName , String clusterName );
394
+ protected abstract Store fetchStoreFromRemote (String storeName , String clusterName );
403
395
404
- protected abstract StoreMetaValue getStoreMetaValue (String storeName , StoreMetaKey key );
405
-
406
- // Helper function with common code for retrieving StoreConfig from meta system store.
407
- protected StoreConfig getStoreConfigFromMetaSystemStore (String storeName ) {
408
- StoreClusterConfig clusterConfig = getStoreMetaValue (
409
- storeName ,
410
- MetaStoreDataType .STORE_CLUSTER_CONFIG
411
- .getStoreMetaKey (Collections .singletonMap (KEY_STRING_STORE_NAME , storeName ))).storeClusterConfig ;
412
- return new StoreConfig (clusterConfig );
413
- }
414
-
415
- // Helper function with common code for retrieving SchemaData from meta system store.
416
- protected SchemaData getSchemaDataFromMetaSystemStore (String storeName ) {
417
- SchemaData schemaData = schemaMap .get (storeName );
418
- SchemaEntry keySchema ;
419
- if (schemaData == null ) {
420
- // Retrieve the key schema and initialize SchemaData only if it's not cached yet.
421
- StoreMetaKey keySchemaKey = MetaStoreDataType .STORE_KEY_SCHEMAS
422
- .getStoreMetaKey (Collections .singletonMap (KEY_STRING_STORE_NAME , storeName ));
423
- Map <CharSequence , CharSequence > keySchemaMap =
424
- getStoreMetaValue (storeName , keySchemaKey ).storeKeySchemas .keySchemaMap ;
425
- if (keySchemaMap .isEmpty ()) {
426
- throw new VeniceException ("No key schema found for store: " + storeName );
427
- }
428
- Map .Entry <CharSequence , CharSequence > keySchemaEntry = keySchemaMap .entrySet ().iterator ().next ();
429
- keySchema =
430
- new SchemaEntry (Integer .parseInt (keySchemaEntry .getKey ().toString ()), keySchemaEntry .getValue ().toString ());
431
- schemaData = new SchemaData (storeName , keySchema );
432
- }
433
- StoreMetaKey valueSchemaKey = MetaStoreDataType .STORE_VALUE_SCHEMAS
434
- .getStoreMetaKey (Collections .singletonMap (KEY_STRING_STORE_NAME , storeName ));
435
- Map <CharSequence , CharSequence > valueSchemaMap =
436
- getStoreMetaValue (storeName , valueSchemaKey ).storeValueSchemas .valueSchemaMap ;
437
- // Check the value schema string, if it's empty then try to query the other key space for individual value schema.
438
- for (Map .Entry <CharSequence , CharSequence > entry : valueSchemaMap .entrySet ()) {
439
- // Check if we already have the corresponding value schema
440
- int valueSchemaId = Integer .parseInt (entry .getKey ().toString ());
441
- if (schemaData .getValueSchema (valueSchemaId ) != null ) {
442
- continue ;
443
- }
444
- if (entry .getValue ().toString ().isEmpty ()) {
445
- // The value schemas might be too large to be stored in a single K/V.
446
- StoreMetaKey individualValueSchemaKey =
447
- MetaStoreDataType .STORE_VALUE_SCHEMA .getStoreMetaKey (new HashMap <String , String >() {
448
- {
449
- put (KEY_STRING_STORE_NAME , storeName );
450
- put (KEY_STRING_SCHEMA_ID , entry .getKey ().toString ());
451
- }
452
- });
453
- // Empty string is not a valid value schema therefore it's safe to throw exceptions if we also cannot find it in
454
- // the individual value schema key space.
455
- String valueSchema =
456
- getStoreMetaValue (storeName , individualValueSchemaKey ).storeValueSchema .valueSchema .toString ();
457
- schemaData .addValueSchema (new SchemaEntry (valueSchemaId , valueSchema ));
458
- } else {
459
- schemaData .addValueSchema (new SchemaEntry (valueSchemaId , entry .getValue ().toString ()));
460
- }
461
- }
462
- return schemaData ;
463
- }
396
+ protected abstract SchemaData getSchemaData (String storeName );
464
397
465
398
protected Store putStore (Store newStore ) {
466
399
// Workaround to make old metadata compatible with new fields
@@ -516,11 +449,11 @@ protected void notifyStoreChanged(Store store) {
516
449
}
517
450
}
518
451
519
- protected SchemaData getAndCacheSchemaDataFromSystemStore (String storeName ) {
452
+ protected SchemaData getAndCacheSchemaData (String storeName ) {
520
453
if (!hasStore (storeName )) {
521
454
throw new VeniceNoStoreException (storeName );
522
455
}
523
- SchemaData schemaData = getSchemaDataFromSystemStore (storeName );
456
+ SchemaData schemaData = getSchemaData (storeName );
524
457
schemaMap .put (storeName , schemaData );
525
458
return schemaData ;
526
459
}
@@ -532,7 +465,7 @@ protected SchemaData getAndCacheSchemaDataFromSystemStore(String storeName) {
532
465
private SchemaData getSchemaDataFromReadThroughCache (String storeName ) throws VeniceNoStoreException {
533
466
SchemaData schemaData = schemaMap .get (storeName );
534
467
if (schemaData == null ) {
535
- schemaData = getAndCacheSchemaDataFromSystemStore (storeName );
468
+ schemaData = getAndCacheSchemaData (storeName );
536
469
}
537
470
return schemaData ;
538
471
}
@@ -545,8 +478,6 @@ protected SchemaEntry getValueSchemaInternally(String storeName, int id) {
545
478
return schemaData .getValueSchema (id );
546
479
}
547
480
548
- protected abstract SchemaData getSchemaDataFromSystemStore (String storeName );
549
-
550
481
/**
551
482
* This function is used to remove schema entry for the given store from local cache,
552
483
* and related listeners as well.
0 commit comments