This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workload Service] Proof-of-concept: one row two cells (#6453)
* v0 * atlasdb store * fix tests * stash * stash * working v0 * working v0 * refactor * add more tests * boo * templates and runners * Cleanup and tests: CTR * CTR: concretions to abstractions * boo * rocket launch * self-CR * final * dependencies * proof-of-concept: one row two cells * la campanella * la campanella * explanations * bleh * fixes * boo * Slash and burn * workflow behaves differently * fix * boo * cleanup * final * clair de lune * CR checkpoint * CR * CR * Add witnessed transaction actions * fixes --------- Co-authored-by: Sam Kramer <[email protected]>
- Loading branch information
1 parent
868f3e7
commit 409a00b
Showing
10 changed files
with
420 additions
and
15 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...d-server-api/src/main/java/com/palantir/atlasdb/workload/workflow/TableConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.atlasdb.workload.workflow; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.palantir.atlasdb.workload.store.IsolationLevel; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Immutable | ||
@JsonSerialize(as = ImmutableTableConfiguration.class) | ||
@JsonDeserialize(as = ImmutableTableConfiguration.class) | ||
public interface TableConfiguration { | ||
String tableName(); | ||
|
||
IsolationLevel isolationLevel(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...n/java/com/palantir/atlasdb/workload/workflow/SingleRowTwoCellsWorkflowConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.atlasdb.workload.workflow; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.google.common.util.concurrent.RateLimiter; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Immutable | ||
@JsonSerialize(as = ImmutableSingleRowTwoCellsWorkflowConfiguration.class) | ||
@JsonDeserialize(as = ImmutableSingleRowTwoCellsWorkflowConfiguration.class) | ||
@JsonTypeName(SingleRowTwoCellsWorkflowConfiguration.TYPE) | ||
public interface SingleRowTwoCellsWorkflowConfiguration extends WorkflowConfiguration { | ||
String TYPE = "SINGLE_ROW_TWO_CELLS"; | ||
|
||
TableConfiguration tableConfiguration(); | ||
|
||
@Value.Default | ||
default double rateLimit() { | ||
return 100; | ||
} | ||
|
||
@Value.Lazy | ||
default RateLimiter transactionRateLimiter() { | ||
return RateLimiter.create(rateLimit()); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...rver/src/main/java/com/palantir/atlasdb/workload/workflow/SingleRowTwoCellsWorkflows.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.atlasdb.workload.workflow; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Streams; | ||
import com.google.common.util.concurrent.ListeningExecutorService; | ||
import com.palantir.atlasdb.workload.store.ImmutableWorkloadCell; | ||
import com.palantir.atlasdb.workload.store.TransactionStore; | ||
import com.palantir.atlasdb.workload.store.WorkloadCell; | ||
import com.palantir.atlasdb.workload.transaction.DeleteTransactionAction; | ||
import com.palantir.atlasdb.workload.transaction.ReadTransactionAction; | ||
import com.palantir.atlasdb.workload.transaction.TransactionAction; | ||
import com.palantir.atlasdb.workload.transaction.WriteTransactionAction; | ||
import com.palantir.atlasdb.workload.transaction.witnessed.WitnessedTransaction; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Consider a single row in a database that has two cells, which should between them maintain the invariant that | ||
* at most one cell has a value (this workflow is extremely common in AtlasDB Proxy). This workflow maintains | ||
* concurrent transactions that read the row (both cells), and then sends an update to one of the cells and attempts | ||
* to delete the other. | ||
*/ | ||
public final class SingleRowTwoCellsWorkflows { | ||
private static final int SINGLE_ROW = 1; | ||
private static final int FIRST_COLUMN = 1; | ||
private static final int SECOND_COLUMN = 2; | ||
|
||
@VisibleForTesting | ||
static final WorkloadCell FIRST_CELL = ImmutableWorkloadCell.of(SINGLE_ROW, FIRST_COLUMN); | ||
|
||
@VisibleForTesting | ||
static final WorkloadCell SECOND_CELL = ImmutableWorkloadCell.of(SINGLE_ROW, SECOND_COLUMN); | ||
|
||
private SingleRowTwoCellsWorkflows() { | ||
// static factory | ||
} | ||
|
||
public static Workflow createSingleRowTwoCell( | ||
TransactionStore store, | ||
SingleRowTwoCellsWorkflowConfiguration singleRowTwoCellsWorkflowConfiguration, | ||
ListeningExecutorService executionExecutor) { | ||
return DefaultWorkflow.create( | ||
store, | ||
(txnStore, index) -> run(txnStore, index, singleRowTwoCellsWorkflowConfiguration), | ||
singleRowTwoCellsWorkflowConfiguration, | ||
executionExecutor); | ||
} | ||
|
||
private static Optional<WitnessedTransaction> run( | ||
TransactionStore store, int taskIndex, SingleRowTwoCellsWorkflowConfiguration workflowConfiguration) { | ||
workflowConfiguration.transactionRateLimiter().acquire(); | ||
|
||
List<TransactionAction> transactionActions = createTransactionActions( | ||
taskIndex, workflowConfiguration.tableConfiguration().tableName()); | ||
return store.readWrite(transactionActions); | ||
} | ||
|
||
@VisibleForTesting | ||
static List<TransactionAction> createTransactionActions(int taskIndex, String tableName) { | ||
List<TransactionAction> cellReads = createCellReadActions(tableName); | ||
List<TransactionAction> cellUpdates = createCellUpdateActions(taskIndex, tableName); | ||
return Streams.concat(cellReads.stream(), cellUpdates.stream(), cellReads.stream()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@VisibleForTesting | ||
static boolean shouldWriteToFirstCell(int taskIndex) { | ||
return taskIndex % 2 == 0; | ||
} | ||
|
||
private static List<TransactionAction> createCellUpdateActions(int taskIndex, String tableName) { | ||
return shouldWriteToFirstCell(taskIndex) | ||
? ImmutableList.of( | ||
WriteTransactionAction.of(tableName, FIRST_CELL, taskIndex), | ||
DeleteTransactionAction.of(tableName, SECOND_CELL)) | ||
: ImmutableList.of( | ||
DeleteTransactionAction.of(tableName, FIRST_CELL), | ||
WriteTransactionAction.of(tableName, SECOND_CELL, taskIndex)); | ||
} | ||
|
||
private static List<TransactionAction> createCellReadActions(String tableName) { | ||
return ImmutableList.of( | ||
ReadTransactionAction.of(tableName, FIRST_CELL), ReadTransactionAction.of(tableName, SECOND_CELL)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...va/com/palantir/atlasdb/workload/workflow/SingleRowTwoCellsWorkflowConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.atlasdb.workload.workflow; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.util.concurrent.RateLimiter; | ||
import com.palantir.atlasdb.workload.store.IsolationLevel; | ||
import com.palantir.atlasdb.workload.transaction.WorkloadTestHelpers; | ||
import com.palantir.conjure.java.serialization.ObjectMappers; | ||
import org.junit.Test; | ||
|
||
public class SingleRowTwoCellsWorkflowConfigurationTest { | ||
private static final TableConfiguration TABLE_CONFIGURATION = ImmutableTableConfiguration.builder() | ||
.tableName(WorkloadTestHelpers.TABLE) | ||
.isolationLevel(IsolationLevel.SERIALIZABLE) | ||
.build(); | ||
private static final ObjectMapper OBJECT_MAPPER = ObjectMappers.newServerObjectMapper(); | ||
|
||
static { | ||
OBJECT_MAPPER.registerSubtypes(SingleRowTwoCellsWorkflowConfiguration.class); | ||
} | ||
|
||
@Test | ||
public void rateLimiterCreatedWithConfiguredNumberOfPermits() { | ||
SingleRowTwoCellsWorkflowConfiguration configuration = createWithRateLimit(Double.MIN_NORMAL); | ||
RateLimiter rateLimiter = configuration.transactionRateLimiter(); | ||
assertThat(rateLimiter.tryAcquire()).isTrue(); | ||
assertThat(rateLimiter.tryAcquire()) | ||
.as("the rate limiter granted two requests, but was not configured to accept more than one every" | ||
+ " ~2.2 * 10^308 seconds") | ||
.isFalse(); | ||
} | ||
|
||
@Test | ||
public void deserializationIsInverseOfSerialization() throws JsonProcessingException { | ||
SingleRowTwoCellsWorkflowConfiguration configuration = createWithRateLimit(5); | ||
assertThat(OBJECT_MAPPER.readValue( | ||
OBJECT_MAPPER.writeValueAsString(configuration), WorkflowConfiguration.class)) | ||
.isEqualTo(configuration); | ||
} | ||
|
||
@Test | ||
public void rateLimitAccountedForInSerializedForm() throws JsonProcessingException { | ||
assertThat(OBJECT_MAPPER.writeValueAsString(createWithRateLimit(10))) | ||
.isNotEqualTo(OBJECT_MAPPER.writeValueAsString(createWithRateLimit(20))); | ||
} | ||
|
||
private static SingleRowTwoCellsWorkflowConfiguration createWithRateLimit(double rateLimit) { | ||
return ImmutableSingleRowTwoCellsWorkflowConfiguration.builder() | ||
.tableConfiguration(TABLE_CONFIGURATION) | ||
.rateLimit(rateLimit) | ||
.iterationCount(10) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.