Skip to content

Commit 2ae5145

Browse files
committed
Fix to version metadata
1 parent 2b7b8e0 commit 2ae5145

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

core/src/main/java/com/scalar/db/storage/objectstorage/ObjectStorageNamespaceMetadata.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,33 @@
66

77
@Immutable
88
public class ObjectStorageNamespaceMetadata {
9+
public static final Integer DEFAULT_VERSION = 1;
910
private final String name;
11+
private final Integer version;
1012

1113
// The default constructor is required by Jackson to deserialize JSON object
1214
@SuppressWarnings("unused")
1315
public ObjectStorageNamespaceMetadata() {
14-
this(null);
16+
this(null, null);
1517
}
1618

17-
public ObjectStorageNamespaceMetadata(@Nullable String name) {
19+
public ObjectStorageNamespaceMetadata(@Nullable String name, @Nullable Integer version) {
1820
this.name = name != null ? name : "";
21+
this.version = version != null ? version : DEFAULT_VERSION;
22+
}
23+
24+
public ObjectStorageNamespaceMetadata(@Nullable String name) {
25+
this(name, DEFAULT_VERSION);
1926
}
2027

2128
public String getName() {
2229
return name;
2330
}
2431

32+
public Integer getVersion() {
33+
return version;
34+
}
35+
2536
@Override
2637
public boolean equals(Object o) {
2738
if (this == o) {
@@ -32,11 +43,11 @@ public boolean equals(Object o) {
3243
}
3344
ObjectStorageNamespaceMetadata that = (ObjectStorageNamespaceMetadata) o;
3445

35-
return name.equals(that.name);
46+
return name.equals(that.name) && version.equals(that.version);
3647
}
3748

3849
@Override
3950
public int hashCode() {
40-
return Objects.hash(name);
51+
return Objects.hash(name, version);
4152
}
4253
}

core/src/main/java/com/scalar/db/storage/objectstorage/ObjectStorageTableMetadata.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@
1919
@SuppressFBWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
2020
@Immutable
2121
public class ObjectStorageTableMetadata {
22+
public static final Integer DEFAULT_VERSION = 1;
2223
private final LinkedHashSet<String> partitionKeyNames;
2324
private final LinkedHashSet<String> clusteringKeyNames;
2425
private final Map<String, String> clusteringOrders;
2526
private final Set<String> secondaryIndexNames;
2627
private final Map<String, String> columns;
28+
private final Integer version;
2729

2830
// The default constructor is required by Jackson to deserialize JSON object
2931
public ObjectStorageTableMetadata() {
30-
this(null, null, null, null, null);
32+
this(null, null, null, null, null, null);
3133
}
3234

3335
public ObjectStorageTableMetadata(
3436
@Nullable LinkedHashSet<String> partitionKeyNames,
3537
@Nullable LinkedHashSet<String> clusteringKeyNames,
3638
@Nullable Map<String, String> clusteringOrders,
3739
@Nullable Set<String> secondaryIndexNames,
38-
@Nullable Map<String, String> columns) {
40+
@Nullable Map<String, String> columns,
41+
@Nullable Integer version) {
3942
this.partitionKeyNames =
4043
partitionKeyNames != null ? new LinkedHashSet<>(partitionKeyNames) : new LinkedHashSet<>();
4144
this.clusteringKeyNames =
@@ -47,9 +50,10 @@ public ObjectStorageTableMetadata(
4750
this.secondaryIndexNames =
4851
secondaryIndexNames != null ? new HashSet<>(secondaryIndexNames) : Collections.emptySet();
4952
this.columns = columns != null ? new HashMap<>(columns) : Collections.emptyMap();
53+
this.version = version != null ? version : DEFAULT_VERSION;
5054
}
5155

52-
public ObjectStorageTableMetadata(TableMetadata tableMetadata) {
56+
public ObjectStorageTableMetadata(TableMetadata tableMetadata, Integer version) {
5357
Map<String, String> clusteringOrders =
5458
tableMetadata.getClusteringKeyNames().stream()
5559
.collect(
@@ -67,6 +71,11 @@ public ObjectStorageTableMetadata(TableMetadata tableMetadata) {
6771
this.clusteringOrders = clusteringOrders;
6872
this.secondaryIndexNames = tableMetadata.getSecondaryIndexNames();
6973
this.columns = columnTypeByName;
74+
this.version = version;
75+
}
76+
77+
public ObjectStorageTableMetadata(TableMetadata tableMetadata) {
78+
this(tableMetadata, DEFAULT_VERSION);
7079
}
7180

7281
private ObjectStorageTableMetadata(Builder builder) {
@@ -75,7 +84,8 @@ private ObjectStorageTableMetadata(Builder builder) {
7584
builder.clusteringKeyNames,
7685
builder.clusteringOrders,
7786
builder.secondaryIndexNames,
78-
builder.columns);
87+
builder.columns,
88+
builder.version);
7989
}
8090

8191
public LinkedHashSet<String> getPartitionKeyNames() {
@@ -98,6 +108,10 @@ public Map<String, String> getColumns() {
98108
return columns;
99109
}
100110

111+
public Integer getVersion() {
112+
return version;
113+
}
114+
101115
@Override
102116
public boolean equals(Object o) {
103117
if (this == o) {
@@ -111,13 +125,19 @@ public boolean equals(Object o) {
111125
&& Objects.equals(clusteringKeyNames, that.clusteringKeyNames)
112126
&& Objects.equals(clusteringOrders, that.clusteringOrders)
113127
&& Objects.equals(secondaryIndexNames, that.secondaryIndexNames)
114-
&& Objects.equals(columns, that.columns);
128+
&& Objects.equals(columns, that.columns)
129+
&& Objects.equals(version, that.version);
115130
}
116131

117132
@Override
118133
public int hashCode() {
119134
return Objects.hash(
120-
partitionKeyNames, clusteringKeyNames, clusteringOrders, secondaryIndexNames, columns);
135+
partitionKeyNames,
136+
clusteringKeyNames,
137+
clusteringOrders,
138+
secondaryIndexNames,
139+
columns,
140+
version);
121141
}
122142

123143
public TableMetadata toTableMetadata() {
@@ -169,6 +189,7 @@ public static final class Builder {
169189
private Map<String, String> clusteringOrders;
170190
private Set<String> secondaryIndexNames;
171191
private Map<String, String> columns;
192+
private Integer version;
172193

173194
private Builder() {}
174195

@@ -197,6 +218,11 @@ public ObjectStorageTableMetadata.Builder columns(Map<String, String> val) {
197218
return this;
198219
}
199220

221+
public ObjectStorageTableMetadata.Builder version(Integer val) {
222+
version = val;
223+
return this;
224+
}
225+
200226
public ObjectStorageTableMetadata build() {
201227
return new ObjectStorageTableMetadata(this);
202228
}

0 commit comments

Comments
 (0)