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.
Handle KAE (or other exceptions of similar type) in the future when w…
…itnessing transactions (#6533) Handles transactions that may or may have not been witnessed due to errors (such as KeyAlreadyExistsException) in the workload server.
- Loading branch information
1 parent
f2f0426
commit 2857ac2
Showing
21 changed files
with
464 additions
and
69 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
...n/java/com/palantir/atlasdb/workload/transaction/witnessed/FullyWitnessedTransaction.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,34 @@ | ||
/* | ||
* (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.transaction.witnessed; | ||
|
||
import org.immutables.value.Value; | ||
|
||
/** | ||
* For transactions that we know for certain we've witnessed. | ||
*/ | ||
@Value.Immutable | ||
public interface FullyWitnessedTransaction extends WitnessedTransaction { | ||
@Override | ||
default <T> T accept(WitnessedTransactionVisitor<T> visitor) { | ||
return visitor.visit(this); | ||
} | ||
|
||
static ImmutableFullyWitnessedTransaction.Builder builder() { | ||
return ImmutableFullyWitnessedTransaction.builder(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...n/java/com/palantir/atlasdb/workload/transaction/witnessed/MaybeWitnessedTransaction.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,52 @@ | ||
/* | ||
* (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.transaction.witnessed; | ||
|
||
import com.palantir.logsafe.Preconditions; | ||
import org.immutables.value.Value; | ||
|
||
/** | ||
* For transactions that we witnessed, but are in a state which we are | ||
* unsure if they have committed or not due to failures. | ||
*/ | ||
@Value.Immutable | ||
public interface MaybeWitnessedTransaction extends WitnessedTransaction { | ||
@Value.Check | ||
default void check() { | ||
Preconditions.checkArgument( | ||
commitTimestamp().isPresent(), | ||
"Given how the transaction protocol works, a transaction for which we haven't retrieved the commit " | ||
+ "timestamp has not written anything of significance to the database"); | ||
} | ||
|
||
@Override | ||
default <T> T accept(WitnessedTransactionVisitor<T> visitor) { | ||
return visitor.visit(this); | ||
} | ||
|
||
static ImmutableMaybeWitnessedTransaction.Builder builder() { | ||
return ImmutableMaybeWitnessedTransaction.builder(); | ||
} | ||
|
||
default FullyWitnessedTransaction toFullyWitnessed() { | ||
return FullyWitnessedTransaction.builder() | ||
.startTimestamp(startTimestamp()) | ||
.commitTimestamp(commitTimestamp()) | ||
.actions(actions()) | ||
.build(); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
...java/com/palantir/atlasdb/workload/transaction/witnessed/WitnessedTransactionVisitor.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,23 @@ | ||
/* | ||
* (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.transaction.witnessed; | ||
|
||
public interface WitnessedTransactionVisitor<T> { | ||
T visit(FullyWitnessedTransaction witnessedTransaction); | ||
|
||
T visit(MaybeWitnessedTransaction maybeWitnessedTransaction); | ||
} |
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
68 changes: 68 additions & 0 deletions
68
...va/com/palantir/atlasdb/workload/transaction/witnessed/MaybeWitnessedTransactionTest.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,68 @@ | ||
/* | ||
* (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.transaction.witnessed; | ||
|
||
import static com.palantir.logsafe.testing.Assertions.assertThatLoggableExceptionThrownBy; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; | ||
import java.util.List; | ||
import org.junit.Test; | ||
|
||
public class MaybeWitnessedTransactionTest { | ||
|
||
private static final Long START_TIMESTAMP = 100L; | ||
private static final Long COMMIT_TIMESTAMP = 200L; | ||
|
||
@Test | ||
public void throwsWhenCommitTimestampIsNotPresentOnCreation() { | ||
assertThatLoggableExceptionThrownBy(() -> MaybeWitnessedTransaction.builder() | ||
.startTimestamp(START_TIMESTAMP) | ||
.build()) | ||
.isInstanceOf(SafeIllegalArgumentException.class) | ||
.hasMessageContaining( | ||
"Given how the transaction protocol works, a transaction for which we haven't retrieved the" | ||
+ " commit timestamp"); | ||
} | ||
|
||
@Test | ||
public void doesNotThrowWhenCommitTimestampPresentOnCreation() { | ||
assertThatCode(() -> MaybeWitnessedTransaction.builder() | ||
.startTimestamp(START_TIMESTAMP) | ||
.commitTimestamp(COMMIT_TIMESTAMP) | ||
.build()) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
public void toFullyWitnessedCopiesArgumentsCorrectly() { | ||
WitnessedWriteTransactionAction writeTransactionAction = mock(WitnessedWriteTransactionAction.class); | ||
WitnessedReadTransactionAction readTransactionAction = mock(WitnessedReadTransactionAction.class); | ||
List<WitnessedTransactionAction> actions = List.of(readTransactionAction, writeTransactionAction); | ||
FullyWitnessedTransaction fullyWitnessedTransaction = MaybeWitnessedTransaction.builder() | ||
.startTimestamp(START_TIMESTAMP) | ||
.commitTimestamp(COMMIT_TIMESTAMP) | ||
.actions(actions) | ||
.build() | ||
.toFullyWitnessed(); | ||
assertThat(fullyWitnessedTransaction.startTimestamp()).isEqualTo(START_TIMESTAMP); | ||
assertThat(fullyWitnessedTransaction.commitTimestamp()).contains(COMMIT_TIMESTAMP); | ||
assertThat(fullyWitnessedTransaction.actions()).containsExactlyElementsOf(actions); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...ntir/atlasdb/workload/transaction/witnessed/OnlyCommittedWitnessedTransactionVisitor.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,42 @@ | ||
/* | ||
* (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.transaction.witnessed; | ||
|
||
import com.palantir.atlasdb.workload.store.ReadOnlyTransactionStore; | ||
import java.util.Optional; | ||
|
||
public final class OnlyCommittedWitnessedTransactionVisitor | ||
implements WitnessedTransactionVisitor<Optional<FullyWitnessedTransaction>> { | ||
|
||
private final ReadOnlyTransactionStore readOnlyTransactionStore; | ||
|
||
public OnlyCommittedWitnessedTransactionVisitor(ReadOnlyTransactionStore readOnlyTransactionStore) { | ||
this.readOnlyTransactionStore = readOnlyTransactionStore; | ||
} | ||
|
||
@Override | ||
public Optional<FullyWitnessedTransaction> visit(FullyWitnessedTransaction witnessedTransaction) { | ||
return Optional.of(witnessedTransaction); | ||
} | ||
|
||
@Override | ||
public Optional<FullyWitnessedTransaction> visit(MaybeWitnessedTransaction maybeWitnessedTransaction) { | ||
return readOnlyTransactionStore.isCommitted(maybeWitnessedTransaction.startTimestamp()) | ||
? Optional.of(maybeWitnessedTransaction.toFullyWitnessed()) | ||
: Optional.empty(); | ||
} | ||
} |
Oops, something went wrong.