Skip to content

Commit 1560deb

Browse files
authored
[common][compat] Add previousCurrentVersion field to track version swap history (linkedin#2433)
1 parent a7f4d1e commit 1560deb

22 files changed

Lines changed: 251 additions & 5 deletions

File tree

build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ subprojects {
327327
// when actually using the new protocol. Example to pin KME to v12 when introducing v13:
328328
// project(':internal:venice-common').file('src/main/resources/avro/KafkaMessageEnvelope/v12', PathValidation.DIRECTORY)
329329
def versionOverrides = [
330-
project(':internal:venice-common').file('src/main/resources/avro/StoreMetaValue/v39', PathValidation.DIRECTORY),
331-
project(':services:venice-controller').file('src/main/resources/avro/AdminOperation/v94', PathValidation.DIRECTORY)
332330
]
333331

334332
def schemaDirs = [sourceDir]

internal/venice-common/src/main/java/com/linkedin/venice/controllerapi/ControllerApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ public class ControllerApiConstants {
281281
public static final String STORE_LIFECYCLE_HOOKS_LIST = "store_lifecycle_hooks_list";
282282
public static final String KEY_URN_COMPRESSION_ENABLED = "key_urn_compression_enabled";
283283
public static final String KEY_URN_FIELDS = "key_urn_fields";
284+
public static final String PREVIOUS_CURRENT_VERSION = "previous_current_version";
284285

285286
/**
286287
* Params for repush job

internal/venice-common/src/main/java/com/linkedin/venice/controllerapi/UpdateStoreQueryParams.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import static com.linkedin.venice.controllerapi.ControllerApiConstants.PARTITIONER_PARAMS;
5555
import static com.linkedin.venice.controllerapi.ControllerApiConstants.PARTITION_COUNT;
5656
import static com.linkedin.venice.controllerapi.ControllerApiConstants.PERSONA_NAME;
57+
import static com.linkedin.venice.controllerapi.ControllerApiConstants.PREVIOUS_CURRENT_VERSION;
5758
import static com.linkedin.venice.controllerapi.ControllerApiConstants.PUSH_STREAM_SOURCE_ADDRESS;
5859
import static com.linkedin.venice.controllerapi.ControllerApiConstants.READ_COMPUTATION_ENABLED;
5960
import static com.linkedin.venice.controllerapi.ControllerApiConstants.READ_QUOTA_IN_CU;
@@ -918,6 +919,14 @@ public Optional<List<String>> getKeyUrnFields() {
918919
return getStringList(KEY_URN_FIELDS);
919920
}
920921

922+
public UpdateStoreQueryParams setPreviousCurrentVersion(int previousCurrentVersion) {
923+
return putInteger(PREVIOUS_CURRENT_VERSION, previousCurrentVersion);
924+
}
925+
926+
public Optional<Integer> getPreviousCurrentVersion() {
927+
return getInteger(PREVIOUS_CURRENT_VERSION);
928+
}
929+
921930
// ***************** above this line are getters and setters *****************
922931
private UpdateStoreQueryParams putInteger(String name, int value) {
923932
return (UpdateStoreQueryParams) add(name, value);

internal/venice-common/src/main/java/com/linkedin/venice/meta/ReadOnlyStore.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,16 @@ public void setRmdVersionId(int replicationMetadataVersionId) {
709709
throw new UnsupportedOperationException();
710710
}
711711

712+
@Override
713+
public int getPreviousCurrentVersion() {
714+
return this.delegate.getPreviousCurrentVersion();
715+
}
716+
717+
@Override
718+
public void setPreviousCurrentVersion(int previousCurrentVersion) {
719+
throw new UnsupportedOperationException();
720+
}
721+
712722
@Override
713723
public Version cloneVersion() {
714724
return this.delegate.cloneVersion();
@@ -1045,6 +1055,9 @@ public StoreProperties cloneStoreProperties() {
10451055
storeProperties.setStoreLifecycleHooks(convertStoreLifecycleHooks(getStoreLifecycleHooks()));
10461056
storeProperties.setKeyUrnCompressionEnabled(isKeyUrnCompressionEnabled());
10471057
storeProperties.setKeyUrnFields(getKeyUrnFields().stream().map(String::toString).collect(Collectors.toList()));
1058+
storeProperties.setPreviousCurrentVersion(getPreviousCurrentVersion());
1059+
// Set blobDbEnabled to default value - field exists in schema but not yet exposed via Store interface
1060+
storeProperties.setBlobDbEnabled("NOT_SPECIFIED");
10481061

10491062
return storeProperties;
10501063
}
@@ -1765,6 +1778,16 @@ public List<String> getKeyUrnFields() {
17651778
return delegate.getKeyUrnFields();
17661779
}
17671780

1781+
@Override
1782+
public int getPreviousCurrentVersion() {
1783+
return this.delegate.getPreviousCurrentVersion();
1784+
}
1785+
1786+
@Override
1787+
public void setPreviousCurrentVersion(int previousCurrentVersion) {
1788+
throw new UnsupportedOperationException();
1789+
}
1790+
17681791
@Override
17691792
public String toString() {
17701793
return this.delegate.toString();
@@ -1920,6 +1943,9 @@ private static StoreVersion convertVersion(Version version) {
19201943
storeVersion.setKeyUrnCompressionEnabled(version.isKeyUrnCompressionEnabled());
19211944
storeVersion.setKeyUrnFields(version.getKeyUrnFields().stream().map(String::toString).collect(Collectors.toList()));
19221945
storeVersion.setRepushTtlSeconds(version.getRepushTtlSeconds());
1946+
storeVersion.setPreviousCurrentVersion(version.getPreviousCurrentVersion());
1947+
// Set blobDbEnabled to default value - field exists in schema but not yet exposed via Version interface
1948+
storeVersion.setBlobDbEnabled("NOT_SPECIFIED");
19231949

19241950
return storeVersion;
19251951
}

internal/venice-common/src/main/java/com/linkedin/venice/meta/Store.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,8 @@ default IntSet getVersionNumbers() {
385385
void setKeyUrnFields(List<String> keyUrnFields);
386386

387387
List<String> getKeyUrnFields();
388+
389+
int getPreviousCurrentVersion();
390+
391+
void setPreviousCurrentVersion(int previousCurrentVersion);
388392
}

internal/venice-common/src/main/java/com/linkedin/venice/meta/StoreInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public static StoreInfo fromStore(Store store) {
9494
storeInfo.setKeyUrnCompressionEnabled(store.isKeyUrnCompressionEnabled());
9595
storeInfo.setKeyUrnFields(store.getKeyUrnFields());
9696
storeInfo.setFlinkVeniceViewsEnabled(store.isFlinkVeniceViewsEnabled());
97+
storeInfo.setPreviousCurrentVersion(store.getPreviousCurrentVersion());
9798
return storeInfo;
9899
}
99100

@@ -378,6 +379,7 @@ public static StoreInfo fromStore(Store store) {
378379
private boolean keyUrnCompressionEnabled = false;
379380
private List<String> keyUrnFields = new ArrayList<>();
380381
private boolean flinkVeniceViewsEnabled = false;
382+
private int previousCurrentVersion = -1;
381383

382384
public StoreInfo() {
383385
}
@@ -1019,4 +1021,12 @@ public List<String> getKeyUrnFields() {
10191021
public void setKeyUrnFields(List<String> keyUrnFields) {
10201022
this.keyUrnFields = keyUrnFields;
10211023
}
1024+
1025+
public int getPreviousCurrentVersion() {
1026+
return previousCurrentVersion;
1027+
}
1028+
1029+
public void setPreviousCurrentVersion(int previousCurrentVersion) {
1030+
this.previousCurrentVersion = previousCurrentVersion;
1031+
}
10221032
}

internal/venice-common/src/main/java/com/linkedin/venice/meta/SystemStore.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,16 @@ public List<String> getKeyUrnFields() {
837837
return Collections.emptyList();
838838
}
839839

840+
@Override
841+
public int getPreviousCurrentVersion() {
842+
return zkSharedStore.getPreviousCurrentVersion();
843+
}
844+
845+
@Override
846+
public void setPreviousCurrentVersion(int previousCurrentVersion) {
847+
throwUnsupportedOperationException("setPreviousCurrentVersion");
848+
}
849+
840850
@Override
841851
public boolean isGlobalRtDivEnabled() {
842852
return zkSharedStore.isGlobalRtDivEnabled();

internal/venice-common/src/main/java/com/linkedin/venice/meta/Version.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ default void setTimestampMetadataVersionId(int replicationMetadataVersionId) {
314314

315315
List<String> getKeyUrnFields();
316316

317+
int getPreviousCurrentVersion();
318+
319+
void setPreviousCurrentVersion(int previousCurrentVersion);
320+
317321
/**
318322
* Kafka topic name is composed by store name and version.
319323
* <p>

internal/venice-common/src/main/java/com/linkedin/venice/meta/VersionImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,16 @@ public List<String> getKeyUrnFields() {
480480
return this.storeVersion.keyUrnFields.stream().map(Objects::toString).collect(Collectors.toList());
481481
}
482482

483+
@Override
484+
public int getPreviousCurrentVersion() {
485+
return this.storeVersion.previousCurrentVersion;
486+
}
487+
488+
@Override
489+
public void setPreviousCurrentVersion(int previousCurrentVersion) {
490+
this.storeVersion.previousCurrentVersion = previousCurrentVersion;
491+
}
492+
483493
@Override
484494
public StoreVersion dataModel() {
485495
return this.storeVersion;
@@ -568,6 +578,7 @@ public Version cloneVersion() {
568578
clonedVersion.setKeyUrnCompressionEnabled(isKeyUrnCompressionEnabled());
569579
clonedVersion.setKeyUrnFields(getKeyUrnFields());
570580
clonedVersion.setRepushTtlSeconds(getRepushTtlSeconds());
581+
clonedVersion.setPreviousCurrentVersion(getPreviousCurrentVersion());
571582
return clonedVersion;
572583
}
573584

internal/venice-common/src/main/java/com/linkedin/venice/meta/ZKStore.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ public ZKStore(Store store) {
251251
setKeyUrnCompressionEnabled(store.isKeyUrnCompressionEnabled());
252252
setKeyUrnFields(store.getKeyUrnFields());
253253
setFlinkVeniceViewsEnabled(store.isFlinkVeniceViewsEnabled());
254+
setPreviousCurrentVersion(store.getPreviousCurrentVersion());
254255

255256
for (Version storeVersion: store.getVersions()) {
256257
forceAddVersion(storeVersion.cloneVersion(), true);
@@ -308,13 +309,35 @@ public int getCurrentVersion() {
308309
/**
309310
* Set current serving version number of this store. If store is disabled to write, thrown {@link
310311
* StoreDisabledException}.
312+
*
313+
* When a new version is promoted to current, this method also sets the previousCurrentVersion
314+
* field on the NEW current version to track which version was current before.
311315
*/
312316
@Override
313317
public void setCurrentVersion(int currentVersion) {
314318
checkDisableStoreWrite("setStoreCurrentVersion", currentVersion);
315319
// Update the latest version promotion to current timestamp, which is useful for backup version retention.
316320
setLatestVersionPromoteToCurrentTimestamp(System.currentTimeMillis());
321+
322+
// Capture old current version before updating
323+
int oldCurrentVersion = getCurrentVersion();
324+
317325
setCurrentVersionWithoutCheck(currentVersion);
326+
327+
// Set previousCurrentVersion on the NEW current version
328+
if (oldCurrentVersion != Store.NON_EXISTING_VERSION && currentVersion != Store.NON_EXISTING_VERSION) {
329+
updateVersionPreviousCurrentVersion(currentVersion, oldCurrentVersion);
330+
}
331+
}
332+
333+
/** Updates the previousCurrentVersion field on a version. */
334+
private void updateVersionPreviousCurrentVersion(int versionNumber, int previousCurrentVersion) {
335+
for (StoreVersion storeVersion: storeProperties.versions) {
336+
if (storeVersion.number == versionNumber) {
337+
storeVersion.previousCurrentVersion = previousCurrentVersion;
338+
return;
339+
}
340+
}
318341
}
319342

320343
@SuppressWarnings("unused") // Used by Serializer/De-serializer for storing to ZooKeeper
@@ -1105,6 +1128,16 @@ public List<String> getKeyUrnFields() {
11051128
return this.storeProperties.keyUrnFields.stream().map(Objects::toString).collect(Collectors.toList());
11061129
}
11071130

1131+
@Override
1132+
public int getPreviousCurrentVersion() {
1133+
return this.storeProperties.previousCurrentVersion;
1134+
}
1135+
1136+
@Override
1137+
public void setPreviousCurrentVersion(int previousCurrentVersion) {
1138+
this.storeProperties.previousCurrentVersion = previousCurrentVersion;
1139+
}
1140+
11081141
@Override
11091142
public boolean isGlobalRtDivEnabled() {
11101143
return this.storeProperties.globalRtDivEnabled;

0 commit comments

Comments
 (0)