Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private Map<String, String> getCreationOptions() {
private void initCassandraAdmin() throws ExecutionException {
StorageFactory factory =
StorageFactory.create(MultiStorageEnv.getPropertiesForCassandra(TEST_NAME));
cassandraAdmin = factory.getAdmin();
cassandraAdmin = factory.getStorageAdmin();

// create tables
cassandraAdmin.createNamespace(NAMESPACE1, true, getCreationOptions());
Expand All @@ -81,7 +81,7 @@ private void initCassandraAdmin() throws ExecutionException {

private void initJdbcAdmin() throws ExecutionException {
StorageFactory factory = StorageFactory.create(MultiStorageEnv.getPropertiesForJdbc(TEST_NAME));
jdbcAdmin = factory.getAdmin();
jdbcAdmin = factory.getStorageAdmin();

// create tables
jdbcAdmin.createNamespace(NAMESPACE1, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public void beforeAll() throws ExecutionException {
private void initCassandraAndCassandraAdmin() throws ExecutionException {
StorageFactory factory =
StorageFactory.create(MultiStorageEnv.getPropertiesForCassandra(TEST_NAME));
cassandraAdmin = factory.getAdmin();
cassandraAdmin = factory.getStorageAdmin();
createTables(cassandraAdmin);
cassandra = factory.getStorage();
}

private void initJdbcDatabaseAndJdbcAdmin() throws ExecutionException {
StorageFactory factory = StorageFactory.create(MultiStorageEnv.getPropertiesForJdbc(TEST_NAME));
jdbcAdmin = factory.getAdmin();
jdbcAdmin = factory.getStorageAdmin();
createTables(jdbcAdmin);
jdbcDatabase = factory.getStorage();
}
Expand Down Expand Up @@ -1189,28 +1189,32 @@ public void operation_WhenDefaultNamespaceGiven_ShouldWorkProperly() {
}

private int getCol1Value(Result result) {
assertThat(result.getValue(COL_NAME1).isPresent()).isTrue();
return result.getValue(COL_NAME1).get().getAsInt();
assertThat(result.contains(COL_NAME1)).isTrue();
assertThat(result.isNull(COL_NAME1)).isFalse();
return result.getInt(COL_NAME1);
}

private String getCol2Value(Result result) {
assertThat(result.getValue(COL_NAME2).isPresent()).isTrue();
assertThat(result.getValue(COL_NAME2).get().getAsString().isPresent()).isTrue();
return result.getValue(COL_NAME2).get().getAsString().get();
assertThat(result.contains(COL_NAME2)).isTrue();
assertThat(result.isNull(COL_NAME2)).isFalse();
return result.getText(COL_NAME2);
}

private int getCol3Value(Result result) {
assertThat(result.getValue(COL_NAME3).isPresent()).isTrue();
return result.getValue(COL_NAME3).get().getAsInt();
assertThat(result.contains(COL_NAME3)).isTrue();
assertThat(result.isNull(COL_NAME3)).isFalse();
return result.getInt(COL_NAME3);
}

private int getCol4Value(Result result) {
assertThat(result.getValue(COL_NAME4).isPresent()).isTrue();
return result.getValue(COL_NAME4).get().getAsInt();
assertThat(result.contains(COL_NAME4)).isTrue();
assertThat(result.isNull(COL_NAME4)).isFalse();
return result.getInt(COL_NAME4);
}

private boolean getCol5Value(Result result) {
assertThat(result.getValue(COL_NAME5).isPresent()).isTrue();
return result.getValue(COL_NAME5).get().getAsBoolean();
assertThat(result.contains(COL_NAME5)).isTrue();
assertThat(result.isNull(COL_NAME5)).isFalse();
return result.getBoolean(COL_NAME5);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.scalar.db.exception.storage.NoMutationException;
import com.scalar.db.io.DataType;
import com.scalar.db.io.Key;
import com.scalar.db.io.Value;
import com.scalar.db.transaction.consensuscommit.CoordinatorGroupCommitter.CoordinatorGroupCommitKeyManipulator;
import com.scalar.db.util.groupcommit.GroupCommitKeyManipulator.Keys;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand Down Expand Up @@ -394,20 +393,15 @@ public static class State {

public State(Result result) throws CoordinatorException {
checkNotMissingRequired(result);
id = result.getValue(Attribute.ID).get().getAsString().get();
state = TransactionState.getInstance(result.getValue(Attribute.STATE).get().getAsInt());
createdAt = result.getValue(Attribute.CREATED_AT).get().getAsLong();
Optional<Value<?>> childIdsOpt = result.getValue(Attribute.CHILD_IDS);
Optional<String> childIdsStrOpt;
if (childIdsOpt.isPresent()) {
childIdsStrOpt = childIdsOpt.get().getAsString();
id = result.getText(Attribute.ID);
state = TransactionState.getInstance(result.getInt(Attribute.STATE));
createdAt = result.getBigInt(Attribute.CREATED_AT);
String childIdsStr = result.getText(Attribute.CHILD_IDS);
if (childIdsStr != null) {
childIds = Splitter.on(CHILD_IDS_DELIMITER).omitEmptyStrings().splitToList(childIdsStr);
} else {
childIdsStrOpt = Optional.empty();
childIds = EMPTY_CHILD_IDS;
}
childIds =
childIdsStrOpt
.map(s -> Splitter.on(CHILD_IDS_DELIMITER).omitEmptyStrings().splitToList(s))
.orElse(EMPTY_CHILD_IDS);
}

public State(String id, TransactionState state) {
Expand Down Expand Up @@ -486,16 +480,13 @@ public int hashCode() {
}

private void checkNotMissingRequired(Result result) throws CoordinatorException {
if (!result.getValue(Attribute.ID).isPresent()
|| !result.getValue(Attribute.ID).get().getAsString().isPresent()) {
if (result.isNull(Attribute.ID) || result.getText(Attribute.ID) == null) {
throw new CoordinatorException("id is missing in the coordinator state");
}
if (!result.getValue(Attribute.STATE).isPresent()
|| result.getValue(Attribute.STATE).get().getAsInt() == 0) {
if (result.isNull(Attribute.STATE) || result.getInt(Attribute.STATE) == 0) {
throw new CoordinatorException("state is missing in the coordinator state");
}
if (!result.getValue(Attribute.CREATED_AT).isPresent()
|| result.getValue(Attribute.CREATED_AT).get().getAsLong() == 0) {
if (result.isNull(Attribute.CREATED_AT) || result.getBigInt(Attribute.CREATED_AT) == 0) {
throw new CoordinatorException("created_at is missing in the coordinator state");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ Optional<TransactionResult> read(@Nullable Snapshot.Key key, Get get) throws Cru
if (key == null) {
// Only for a Get with index, the argument `key` is null. In that case, create a key from
// the result
key = new Snapshot.Key(get, result.get());
TableMetadata tableMetadata = getTableMetadata(get);
key = new Snapshot.Key(get, result.get(), tableMetadata);
}

result = executeRecovery(key, get, result.get());
Expand Down Expand Up @@ -186,7 +187,8 @@ Optional<TransactionResult> read(@Nullable Snapshot.Key key, Get get) throws Cru
if (result.isPresent()) {
// Only when we can get the record with the Get with index, we can put it into the read
// set
key = new Snapshot.Key(get, result.get());
TableMetadata tableMetadata = getTableMetadata(get);
key = new Snapshot.Key(get, result.get(), tableMetadata);
putIntoReadSetInSnapshot(key, result);
}
}
Expand Down Expand Up @@ -255,7 +257,8 @@ private LinkedHashMap<Snapshot.Key, TransactionResult> scanInternal(Scan scan)

for (Result r : scanner) {
TransactionResult result = new TransactionResult(r);
Snapshot.Key key = new Snapshot.Key(scan, r);
TableMetadata tableMetadata = getTableMetadata(scan);
Snapshot.Key key = new Snapshot.Key(scan, r, tableMetadata);
Optional<TransactionResult> processedScanResult = processScanResult(key, scan, result);
processedScanResult.ifPresent(res -> results.put(key, res));

Expand Down Expand Up @@ -810,7 +813,8 @@ public Optional<Result> one() throws CrudException {
return Optional.empty();
}

Snapshot.Key key = new Snapshot.Key(scan, r.get());
TableMetadata tableMetadata = getTableMetadata(scan);
Snapshot.Key key = new Snapshot.Key(scan, r.get(), tableMetadata);
TransactionResult result = new TransactionResult(r.get());

Optional<TransactionResult> processedScanResult = processScanResult(key, scan, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ private void validateScanResults(
// Compare the records of the iterators
while (latestResult.isPresent() && originalResultEntry != null) {
TransactionResult latestTxResult = new TransactionResult(latestResult.get());
Key key = new Key(scan, latestTxResult);
Key key = new Key(scan, latestTxResult, tableMetadata);

if (latestTxResult.getId() != null && latestTxResult.getId().equals(id)) {
// The record is inserted/deleted/updated by this transaction
Expand Down Expand Up @@ -744,7 +744,9 @@ private void validateGetWithIndexResult(
.build();

LinkedHashMap<Key, TransactionResult> results = new LinkedHashMap<>(1);
originalResult.ifPresent(r -> results.put(new Snapshot.Key(scanWithIndex, r), r));
TableMetadata tableMetadata = getTableMetadata(scanWithIndex);
originalResult.ifPresent(
r -> results.put(new Snapshot.Key(scanWithIndex, r, tableMetadata), r));

// Validate the result to check if there is no anti-dependency
validateScanResults(storage, scanWithIndex, results, false);
Expand Down Expand Up @@ -812,11 +814,11 @@ public Key(Get get) {
this((Operation) get);
}

public Key(Get get, Result result) {
public Key(Get get, Result result, TableMetadata tableMetadata) {
this.namespace = get.forNamespace().get();
this.table = get.forTable().get();
this.partitionKey = result.getPartitionKey().get();
this.clusteringKey = result.getClusteringKey();
this.partitionKey = ScalarDbUtils.getPartitionKey(result, tableMetadata);
this.clusteringKey = ScalarDbUtils.getClusteringKey(result, tableMetadata);
}

public Key(Put put) {
Expand All @@ -827,11 +829,11 @@ public Key(Delete delete) {
this((Operation) delete);
}

public Key(Scan scan, Result result) {
public Key(Scan scan, Result result, TableMetadata tableMetadata) {
this.namespace = scan.forNamespace().get();
this.table = scan.forTable().get();
this.partitionKey = result.getPartitionKey().get();
this.clusteringKey = result.getClusteringKey();
this.partitionKey = ScalarDbUtils.getPartitionKey(result, tableMetadata);
this.clusteringKey = ScalarDbUtils.getClusteringKey(result, tableMetadata);
}

private Key(Operation operation) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/com/scalar/db/api/DeleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import com.google.common.collect.ImmutableMap;
import com.scalar.db.io.Key;
import com.scalar.db.io.Value;
import java.util.Optional;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class DeleteTest {
Expand All @@ -32,7 +32,7 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() {
Key actual = del.getPartitionKey();

// Assert
assertThat((Iterable<? extends Value<?>>) expected).isEqualTo(actual);
Assertions.<Key>assertThat(expected).isEqualTo(actual);
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/com/scalar/db/api/GetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import com.google.common.collect.ImmutableMap;
import com.scalar.db.io.Key;
import com.scalar.db.io.Value;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class GetTest {
Expand Down Expand Up @@ -48,7 +48,7 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() {
Key actual = get.getPartitionKey();

// Assert
assertThat((Iterable<? extends Value<?>>) expected).isEqualTo(actual);
Assertions.<Key>assertThat(expected).isEqualTo(actual);
}

@Test
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/com/scalar/db/api/PutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class PutTest {
Expand Down Expand Up @@ -64,7 +65,7 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() {
Key actual = put.getPartitionKey();

// Assert
assertThat((Iterable<? extends Value<?>>) expected).isEqualTo(actual);
Assertions.<Key>assertThat(expected).isEqualTo(actual);
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/com/scalar/db/api/ScanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import com.google.common.collect.ImmutableMap;
import com.scalar.db.api.Selection.Conjunction;
import com.scalar.db.io.Key;
import com.scalar.db.io.Value;
import java.util.Collections;
import java.util.Optional;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class ScanTest {
Expand Down Expand Up @@ -96,7 +96,7 @@ public void constructorAndSetters_AllSet_ShouldGetWhatsSet() {
.withLimit(100);

// Assert
assertThat((Iterable<? extends Value<?>>) scan.getPartitionKey()).isEqualTo(partitionKey);
Assertions.<Key>assertThat(scan.getPartitionKey()).isEqualTo(partitionKey);
assertThat(scan.getStartClusteringKey()).isEqualTo(Optional.of(startClusteringKey));
assertThat(scan.getEndClusteringKey()).isEqualTo(Optional.of(endClusteringKey));
assertThat(scan.getProjections()).isEqualTo(Collections.singletonList(ANY_NAME_1));
Expand Down
16 changes: 8 additions & 8 deletions core/src/test/java/com/scalar/db/common/ResultImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public void getValue_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() {

assertThat(result.contains(ANY_COLUMN_NAME_3)).isTrue();
assertThat(result.isNull(ANY_COLUMN_NAME_3)).isFalse();
assertThat(result.getBigInt(ANY_COLUMN_NAME_3)).isEqualTo(BigIntValue.MAX_VALUE);
assertThat(result.getAsObject(ANY_COLUMN_NAME_3)).isEqualTo(BigIntValue.MAX_VALUE);
assertThat(result.getBigInt(ANY_COLUMN_NAME_3)).isEqualTo(BigIntColumn.MAX_VALUE);
assertThat(result.getAsObject(ANY_COLUMN_NAME_3)).isEqualTo(BigIntColumn.MAX_VALUE);

assertThat(result.contains(ANY_COLUMN_NAME_4)).isTrue();
assertThat(result.isNull(ANY_COLUMN_NAME_4)).isFalse();
Expand Down Expand Up @@ -397,8 +397,8 @@ public void getValue_ProperNullValuesGivenInConstructor_ShouldReturnWhatsSet() {

assertThat(result.contains(ANY_COLUMN_NAME_3)).isTrue();
assertThat(result.isNull(ANY_COLUMN_NAME_3)).isFalse();
assertThat(result.getBigInt(ANY_COLUMN_NAME_3)).isEqualTo(BigIntValue.MAX_VALUE);
assertThat(result.getAsObject(ANY_COLUMN_NAME_3)).isEqualTo(BigIntValue.MAX_VALUE);
assertThat(result.getBigInt(ANY_COLUMN_NAME_3)).isEqualTo(BigIntColumn.MAX_VALUE);
assertThat(result.getAsObject(ANY_COLUMN_NAME_3)).isEqualTo(BigIntColumn.MAX_VALUE);

assertThat(result.contains(ANY_COLUMN_NAME_4)).isTrue();
assertThat(result.isNull(ANY_COLUMN_NAME_4)).isFalse();
Expand Down Expand Up @@ -539,8 +539,8 @@ public void getPartitionKey_RequiredValuesGiven_ShouldReturnPartitionKey() {

// Assert
assertThat(key.isPresent()).isTrue();
assertThat(key.get().get().size()).isEqualTo(1);
assertThat(key.get().get().get(0)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1));
assertThat(key.get().getColumns().size()).isEqualTo(1);
assertThat(key.get().getColumns().get(0)).isEqualTo(TextColumn.of(ANY_NAME_1, ANY_TEXT_1));
}

@Test
Expand Down Expand Up @@ -570,8 +570,8 @@ public void getClusteringKey_RequiredValuesGiven_ShouldReturnClusteringKey() {

// Assert
assertThat(key.isPresent()).isTrue();
assertThat(key.get().get().size()).isEqualTo(1);
assertThat(key.get().get().get(0)).isEqualTo(new TextValue(ANY_NAME_2, ANY_TEXT_2));
assertThat(key.get().getColumns().size()).isEqualTo(1);
assertThat(key.get().getColumns().get(0)).isEqualTo(TextColumn.of(ANY_NAME_2, ANY_TEXT_2));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.scalar.db.api.Result;
import com.scalar.db.api.TableMetadata;
import com.scalar.db.io.BigIntColumn;
import com.scalar.db.io.BigIntValue;
import com.scalar.db.io.Column;
import com.scalar.db.io.DataType;
import com.scalar.db.io.DateColumn;
Expand Down Expand Up @@ -81,7 +80,7 @@ public void interpret_ShouldReturnWhatsSet() {
when(row.getString(ANY_NAME_2)).thenReturn(ANY_TEXT_2);
when(row.getBool(ANY_COLUMN_NAME_1)).thenReturn(true);
when(row.getInt(ANY_COLUMN_NAME_2)).thenReturn(Integer.MAX_VALUE);
when(row.getLong(ANY_COLUMN_NAME_3)).thenReturn(BigIntValue.MAX_VALUE);
when(row.getLong(ANY_COLUMN_NAME_3)).thenReturn(BigIntColumn.MAX_VALUE);
when(row.getFloat(ANY_COLUMN_NAME_4)).thenReturn(Float.MAX_VALUE);
when(row.getDouble(ANY_COLUMN_NAME_5)).thenReturn(Double.MAX_VALUE);
when(row.getString(ANY_COLUMN_NAME_6)).thenReturn("string");
Expand Down
Loading