You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by "keith-turner (via GitHub)" <gi...@apache.org> on 2024/11/28 00:54:11 UTC
[PR] Makes seeding a fate transaction more efficient [accumulo]
keith-turner opened a new pull request, #5122:
URL: https://github.com/apache/accumulo/pull/5122
Modified fate to seed fate transaction in single conditional mutation instead of multiple.
fixes #5097
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872374636
##########
core/src/main/java/org/apache/accumulo/core/fate/user/UserFateStore.java:
##########
@@ -123,104 +123,54 @@ public FateId create() {
}
public FateId getFateId() {
- return FateId.from(fateInstanceType, UUID.randomUUID());
+ return fateIdGenerator.newRandomId(type());
}
@Override
- public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
- final var reservation = FateReservation.from(lockID, UUID.randomUUID());
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
final var fateId = fateIdGenerator.fromTypeAndKey(type(), fateKey);
- Optional<FateTxStore<T>> txStore = Optional.empty();
- int maxAttempts = 5;
- FateMutator.Status status = null;
-
- // Only need to retry if it is UNKNOWN
- for (int attempt = 0; attempt < maxAttempts; attempt++) {
- status = newMutator(fateId).requireStatus().putStatus(TStatus.NEW).putKey(fateKey)
- .putReservedTx(reservation).putCreateTime(System.currentTimeMillis()).tryMutate();
- if (status != FateMutator.Status.UNKNOWN) {
- break;
- }
- UtilWaitThread.sleep(100);
+ Supplier<FateMutator<T>> mutatorFactory = () -> newMutator(fateId).requireAbsent()
+ .putKey(fateKey).putCreateTime(System.currentTimeMillis());
+ if (seedTransaction(mutatorFactory, fateKey + " " + fateId, txName, repo, autoCleanUp)) {
+ return Optional.of(fateId);
+ } else {
+ return Optional.empty();
}
+ }
- switch (status) {
- case ACCEPTED:
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- break;
- case REJECTED:
- // If the status is REJECTED, we need to check what about the mutation was REJECTED:
- // 1) Possible something like the following occurred:
- // the first attempt was UNKNOWN but written, the next attempt would be rejected
- // We return the FateTxStore in this case.
- // 2) If there is a collision with existing fate id, throw error
- // 3) If the fate id is already reserved, return an empty optional
- // 4) If the fate id is still NEW/unseeded and unreserved, we can try to reserve it
- try (Scanner scanner = context.createScanner(tableName, Authorizations.EMPTY)) {
- scanner.setRange(getRow(fateId));
- scanner.fetchColumn(TxColumnFamily.STATUS_COLUMN.getColumnFamily(),
- TxColumnFamily.STATUS_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.TX_KEY_COLUMN.getColumnFamily(),
- TxColumnFamily.TX_KEY_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.RESERVATION_COLUMN.getColumnFamily(),
- TxColumnFamily.RESERVATION_COLUMN.getColumnQualifier());
- TStatus statusSeen = TStatus.UNKNOWN;
- Optional<FateKey> fateKeySeen = Optional.empty();
- Optional<FateReservation> reservationSeen = Optional.empty();
-
- for (Entry<Key,Value> entry : scanner) {
- Text colf = entry.getKey().getColumnFamily();
- Text colq = entry.getKey().getColumnQualifier();
- Value val = entry.getValue();
-
- switch (colq.toString()) {
- case TxColumnFamily.STATUS:
- statusSeen = TStatus.valueOf(val.toString());
- break;
- case TxColumnFamily.TX_KEY:
- fateKeySeen = Optional.of(FateKey.deserialize(val.get()));
- break;
- case TxColumnFamily.RESERVATION:
- reservationSeen = Optional.of(FateReservation.deserialize(val.get()));
- break;
- default:
- throw new IllegalStateException("Unexpected column seen: " + colf + ":" + colq);
- }
- }
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ Supplier<FateMutator<T>> mutatorFactory =
+ () -> newMutator(fateId).requireStatus(TStatus.NEW).requireUnreserved().requireAbsentKey();
+ return seedTransaction(mutatorFactory, fateId.canonical(), txName, repo, autoCleanUp);
+ }
- if (statusSeen == TStatus.NEW) {
- verifyFateKey(fateId, fateKeySeen, fateKey);
- // This will be the case if the mutation status is REJECTED but the mutation was written
- if (reservationSeen.isPresent() && reservationSeen.orElseThrow().equals(reservation)) {
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- } else if (reservationSeen.isEmpty()) {
- // NEW/unseeded transaction and not reserved, so we can allow it to be reserved
- // we tryReserve() since another thread may have reserved it since the scan
- txStore = tryReserve(fateId);
- // the status was known before reserving to be NEW,
- // however it could change so check after reserving to avoid race conditions.
- var statusAfterReserve =
- txStore.map(ReadOnlyFateTxStore::getStatus).orElse(TStatus.UNKNOWN);
- if (statusAfterReserve != TStatus.NEW) {
- txStore.ifPresent(txs -> txs.unreserve(Duration.ZERO));
- txStore = Optional.empty();
- }
- }
- } else {
- log.trace(
- "fate id {} tstatus {} fate key {} is reserved {} "
- + "has already been seeded with work (non-NEW status)",
- fateId, statusSeen, fateKeySeen.orElse(null), reservationSeen.isPresent());
- }
- } catch (TableNotFoundException e) {
- throw new IllegalStateException(tableName + " not found!", e);
- }
- break;
- default:
- throw new IllegalStateException("Unknown or unexpected status " + status);
+ private boolean seedTransaction(Supplier<FateMutator<T>> mutatorFactory, String logId,
+ String txName, Repo<T> repo, boolean autoCleanUp) {
+ int maxAttempts = 5;
+ for (int attempt = 0; attempt < maxAttempts; attempt++) {
+ var mutator = mutatorFactory.get();
+ mutator =
+ mutator.putName(serializeTxInfo(txName)).putRepo(1, repo).putStatus(TStatus.SUBMITTED);
+ if (autoCleanUp) {
+ mutator = mutator.putAutoClean(serializeTxInfo(autoCleanUp));
+ }
+ var status = mutator.tryMutate();
+ if (status == FateMutator.Status.ACCEPTED) {
+ // signal to the super class that a new fate transaction was seeded and is ready to run
+ seededTx();
+ return true;
+ } else if (status == FateMutator.Status.REJECTED) {
Review Comment:
Looking at this some more I will make it try to determine what happened. Even thought its just logging, having accurate log message is important for debugging. And I like the info provided by the current log messages, so do not want to remove them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872328619
##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/MetaFateStore.java:
##########
@@ -161,6 +163,52 @@ public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
}
}
+ @Override
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
+ return createAndReserve(fateKey).map(txStore -> {
+ try {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return txStore.getID();
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ });
+ }
+
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ return tryReserve(fateId).map(txStore -> {
+ try {
+ if (txStore.getStatus() == NEW) {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return true;
+ }
+ return false;
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ }).orElseThrow();
+ }
+
+ protected void seedTransaction(String txName, Repo<T> repo, boolean autoCleanUp,
Review Comment:
I think I had this in AbstractFateStore at one point and it needed to be protected there. Copied it and did not change it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872374636
##########
core/src/main/java/org/apache/accumulo/core/fate/user/UserFateStore.java:
##########
@@ -123,104 +123,54 @@ public FateId create() {
}
public FateId getFateId() {
- return FateId.from(fateInstanceType, UUID.randomUUID());
+ return fateIdGenerator.newRandomId(type());
}
@Override
- public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
- final var reservation = FateReservation.from(lockID, UUID.randomUUID());
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
final var fateId = fateIdGenerator.fromTypeAndKey(type(), fateKey);
- Optional<FateTxStore<T>> txStore = Optional.empty();
- int maxAttempts = 5;
- FateMutator.Status status = null;
-
- // Only need to retry if it is UNKNOWN
- for (int attempt = 0; attempt < maxAttempts; attempt++) {
- status = newMutator(fateId).requireStatus().putStatus(TStatus.NEW).putKey(fateKey)
- .putReservedTx(reservation).putCreateTime(System.currentTimeMillis()).tryMutate();
- if (status != FateMutator.Status.UNKNOWN) {
- break;
- }
- UtilWaitThread.sleep(100);
+ Supplier<FateMutator<T>> mutatorFactory = () -> newMutator(fateId).requireAbsent()
+ .putKey(fateKey).putCreateTime(System.currentTimeMillis());
+ if (seedTransaction(mutatorFactory, fateKey + " " + fateId, txName, repo, autoCleanUp)) {
+ return Optional.of(fateId);
+ } else {
+ return Optional.empty();
}
+ }
- switch (status) {
- case ACCEPTED:
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- break;
- case REJECTED:
- // If the status is REJECTED, we need to check what about the mutation was REJECTED:
- // 1) Possible something like the following occurred:
- // the first attempt was UNKNOWN but written, the next attempt would be rejected
- // We return the FateTxStore in this case.
- // 2) If there is a collision with existing fate id, throw error
- // 3) If the fate id is already reserved, return an empty optional
- // 4) If the fate id is still NEW/unseeded and unreserved, we can try to reserve it
- try (Scanner scanner = context.createScanner(tableName, Authorizations.EMPTY)) {
- scanner.setRange(getRow(fateId));
- scanner.fetchColumn(TxColumnFamily.STATUS_COLUMN.getColumnFamily(),
- TxColumnFamily.STATUS_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.TX_KEY_COLUMN.getColumnFamily(),
- TxColumnFamily.TX_KEY_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.RESERVATION_COLUMN.getColumnFamily(),
- TxColumnFamily.RESERVATION_COLUMN.getColumnQualifier());
- TStatus statusSeen = TStatus.UNKNOWN;
- Optional<FateKey> fateKeySeen = Optional.empty();
- Optional<FateReservation> reservationSeen = Optional.empty();
-
- for (Entry<Key,Value> entry : scanner) {
- Text colf = entry.getKey().getColumnFamily();
- Text colq = entry.getKey().getColumnQualifier();
- Value val = entry.getValue();
-
- switch (colq.toString()) {
- case TxColumnFamily.STATUS:
- statusSeen = TStatus.valueOf(val.toString());
- break;
- case TxColumnFamily.TX_KEY:
- fateKeySeen = Optional.of(FateKey.deserialize(val.get()));
- break;
- case TxColumnFamily.RESERVATION:
- reservationSeen = Optional.of(FateReservation.deserialize(val.get()));
- break;
- default:
- throw new IllegalStateException("Unexpected column seen: " + colf + ":" + colq);
- }
- }
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ Supplier<FateMutator<T>> mutatorFactory =
+ () -> newMutator(fateId).requireStatus(TStatus.NEW).requireUnreserved().requireAbsentKey();
+ return seedTransaction(mutatorFactory, fateId.canonical(), txName, repo, autoCleanUp);
+ }
- if (statusSeen == TStatus.NEW) {
- verifyFateKey(fateId, fateKeySeen, fateKey);
- // This will be the case if the mutation status is REJECTED but the mutation was written
- if (reservationSeen.isPresent() && reservationSeen.orElseThrow().equals(reservation)) {
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- } else if (reservationSeen.isEmpty()) {
- // NEW/unseeded transaction and not reserved, so we can allow it to be reserved
- // we tryReserve() since another thread may have reserved it since the scan
- txStore = tryReserve(fateId);
- // the status was known before reserving to be NEW,
- // however it could change so check after reserving to avoid race conditions.
- var statusAfterReserve =
- txStore.map(ReadOnlyFateTxStore::getStatus).orElse(TStatus.UNKNOWN);
- if (statusAfterReserve != TStatus.NEW) {
- txStore.ifPresent(txs -> txs.unreserve(Duration.ZERO));
- txStore = Optional.empty();
- }
- }
- } else {
- log.trace(
- "fate id {} tstatus {} fate key {} is reserved {} "
- + "has already been seeded with work (non-NEW status)",
- fateId, statusSeen, fateKeySeen.orElse(null), reservationSeen.isPresent());
- }
- } catch (TableNotFoundException e) {
- throw new IllegalStateException(tableName + " not found!", e);
- }
- break;
- default:
- throw new IllegalStateException("Unknown or unexpected status " + status);
+ private boolean seedTransaction(Supplier<FateMutator<T>> mutatorFactory, String logId,
+ String txName, Repo<T> repo, boolean autoCleanUp) {
+ int maxAttempts = 5;
+ for (int attempt = 0; attempt < maxAttempts; attempt++) {
+ var mutator = mutatorFactory.get();
+ mutator =
+ mutator.putName(serializeTxInfo(txName)).putRepo(1, repo).putStatus(TStatus.SUBMITTED);
+ if (autoCleanUp) {
+ mutator = mutator.putAutoClean(serializeTxInfo(autoCleanUp));
+ }
+ var status = mutator.tryMutate();
+ if (status == FateMutator.Status.ACCEPTED) {
+ // signal to the super class that a new fate transaction was seeded and is ready to run
+ seededTx();
+ return true;
+ } else if (status == FateMutator.Status.REJECTED) {
Review Comment:
Looking at this some more I will make it try to determine what happened. Even thought its just logging, having accurate log message is important for debugging.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872373378
##########
core/src/main/java/org/apache/accumulo/core/fate/Fate.java:
##########
@@ -403,55 +401,14 @@ public FateId startTransaction() {
public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
boolean autoCleanUp, String goalMessage) {
-
- Optional<FateTxStore<T>> optTxStore = store.createAndReserve(fateKey);
-
- return optTxStore.map(txStore -> {
- var fateId = txStore.getID();
- try {
- Preconditions.checkState(txStore.getStatus() == NEW);
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
- return fateId;
- });
- }
-
- private void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
- String goalMessage, FateTxStore<T> txStore) {
- if (txStore.top() == null) {
- try {
- log.info("Seeding {} {}", fateId, goalMessage);
- txStore.push(repo);
- } catch (StackOverflowException e) {
- // this should not happen
- throw new IllegalStateException(e);
- }
- }
-
- if (autoCleanUp) {
- txStore.setTransactionInfo(TxInfo.AUTO_CLEAN, autoCleanUp);
- }
-
- txStore.setTransactionInfo(TxInfo.TX_NAME, txName);
-
- txStore.setStatus(SUBMITTED);
+ return store.seedTransaction(txName, fateKey, repo, autoCleanUp);
Review Comment:
fixed in https://github.com/apache/accumulo/commit/e47089c5d9e0efa0007c88b535e9bb3f55b4a44a
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872324312
##########
core/src/main/java/org/apache/accumulo/core/fate/user/UserFateStore.java:
##########
@@ -123,104 +123,54 @@ public FateId create() {
}
public FateId getFateId() {
- return FateId.from(fateInstanceType, UUID.randomUUID());
+ return fateIdGenerator.newRandomId(type());
}
@Override
- public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
- final var reservation = FateReservation.from(lockID, UUID.randomUUID());
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
final var fateId = fateIdGenerator.fromTypeAndKey(type(), fateKey);
- Optional<FateTxStore<T>> txStore = Optional.empty();
- int maxAttempts = 5;
- FateMutator.Status status = null;
-
- // Only need to retry if it is UNKNOWN
- for (int attempt = 0; attempt < maxAttempts; attempt++) {
- status = newMutator(fateId).requireStatus().putStatus(TStatus.NEW).putKey(fateKey)
- .putReservedTx(reservation).putCreateTime(System.currentTimeMillis()).tryMutate();
- if (status != FateMutator.Status.UNKNOWN) {
- break;
- }
- UtilWaitThread.sleep(100);
+ Supplier<FateMutator<T>> mutatorFactory = () -> newMutator(fateId).requireAbsent()
+ .putKey(fateKey).putCreateTime(System.currentTimeMillis());
+ if (seedTransaction(mutatorFactory, fateKey + " " + fateId, txName, repo, autoCleanUp)) {
+ return Optional.of(fateId);
+ } else {
+ return Optional.empty();
}
+ }
- switch (status) {
- case ACCEPTED:
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- break;
- case REJECTED:
- // If the status is REJECTED, we need to check what about the mutation was REJECTED:
- // 1) Possible something like the following occurred:
- // the first attempt was UNKNOWN but written, the next attempt would be rejected
- // We return the FateTxStore in this case.
- // 2) If there is a collision with existing fate id, throw error
- // 3) If the fate id is already reserved, return an empty optional
- // 4) If the fate id is still NEW/unseeded and unreserved, we can try to reserve it
- try (Scanner scanner = context.createScanner(tableName, Authorizations.EMPTY)) {
- scanner.setRange(getRow(fateId));
- scanner.fetchColumn(TxColumnFamily.STATUS_COLUMN.getColumnFamily(),
- TxColumnFamily.STATUS_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.TX_KEY_COLUMN.getColumnFamily(),
- TxColumnFamily.TX_KEY_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.RESERVATION_COLUMN.getColumnFamily(),
- TxColumnFamily.RESERVATION_COLUMN.getColumnQualifier());
- TStatus statusSeen = TStatus.UNKNOWN;
- Optional<FateKey> fateKeySeen = Optional.empty();
- Optional<FateReservation> reservationSeen = Optional.empty();
-
- for (Entry<Key,Value> entry : scanner) {
- Text colf = entry.getKey().getColumnFamily();
- Text colq = entry.getKey().getColumnQualifier();
- Value val = entry.getValue();
-
- switch (colq.toString()) {
- case TxColumnFamily.STATUS:
- statusSeen = TStatus.valueOf(val.toString());
- break;
- case TxColumnFamily.TX_KEY:
- fateKeySeen = Optional.of(FateKey.deserialize(val.get()));
- break;
- case TxColumnFamily.RESERVATION:
- reservationSeen = Optional.of(FateReservation.deserialize(val.get()));
- break;
- default:
- throw new IllegalStateException("Unexpected column seen: " + colf + ":" + colq);
- }
- }
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ Supplier<FateMutator<T>> mutatorFactory =
+ () -> newMutator(fateId).requireStatus(TStatus.NEW).requireUnreserved().requireAbsentKey();
+ return seedTransaction(mutatorFactory, fateId.canonical(), txName, repo, autoCleanUp);
+ }
- if (statusSeen == TStatus.NEW) {
- verifyFateKey(fateId, fateKeySeen, fateKey);
- // This will be the case if the mutation status is REJECTED but the mutation was written
- if (reservationSeen.isPresent() && reservationSeen.orElseThrow().equals(reservation)) {
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- } else if (reservationSeen.isEmpty()) {
- // NEW/unseeded transaction and not reserved, so we can allow it to be reserved
- // we tryReserve() since another thread may have reserved it since the scan
- txStore = tryReserve(fateId);
- // the status was known before reserving to be NEW,
- // however it could change so check after reserving to avoid race conditions.
- var statusAfterReserve =
- txStore.map(ReadOnlyFateTxStore::getStatus).orElse(TStatus.UNKNOWN);
- if (statusAfterReserve != TStatus.NEW) {
- txStore.ifPresent(txs -> txs.unreserve(Duration.ZERO));
- txStore = Optional.empty();
- }
- }
- } else {
- log.trace(
- "fate id {} tstatus {} fate key {} is reserved {} "
- + "has already been seeded with work (non-NEW status)",
- fateId, statusSeen, fateKeySeen.orElse(null), reservationSeen.isPresent());
- }
- } catch (TableNotFoundException e) {
- throw new IllegalStateException(tableName + " not found!", e);
- }
- break;
- default:
- throw new IllegalStateException("Unknown or unexpected status " + status);
+ private boolean seedTransaction(Supplier<FateMutator<T>> mutatorFactory, String logId,
+ String txName, Repo<T> repo, boolean autoCleanUp) {
+ int maxAttempts = 5;
+ for (int attempt = 0; attempt < maxAttempts; attempt++) {
+ var mutator = mutatorFactory.get();
+ mutator =
+ mutator.putName(serializeTxInfo(txName)).putRepo(1, repo).putStatus(TStatus.SUBMITTED);
+ if (autoCleanUp) {
+ mutator = mutator.putAutoClean(serializeTxInfo(autoCleanUp));
+ }
+ var status = mutator.tryMutate();
+ if (status == FateMutator.Status.ACCEPTED) {
+ // signal to the super class that a new fate transaction was seeded and is ready to run
+ seededTx();
+ return true;
+ } else if (status == FateMutator.Status.REJECTED) {
Review Comment:
Good point. Looking over the way things works end to end if a lot of effort is made here to determine what happened with unknown then the calling code will not really care (because it just logs the result). However the way the functions are structured that is not obvious and if future calling code did something besides just logging the result then it would not be correct in this corner case. I will try to look at the end to end structure and clean this up to either handle that corner case or make the functions reflect a best effort impl.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "kevinrr888 (via GitHub)" <gi...@apache.org>.
kevinrr888 commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1876861938
##########
core/src/main/java/org/apache/accumulo/core/fate/FateStore.java:
##########
@@ -50,19 +50,22 @@ public interface FateStore<T> extends ReadOnlyFateStore<T> {
FateId create();
/**
- * Creates and reserves a transaction using the given key. If something is already running for the
- * given key, then Optional.empty() will be returned. When this returns a non-empty id, it will be
- * in the new state.
+ * Seeds a transaction with the given repo if it does not exists. Will set the status to
+ * SUBMITTED. Will set the fate key. Will set autoCleanup if true. Will set the creation time.
*
- * <p>
- * In the case where a process dies in the middle of a call to this. If later, another call is
- * made with the same key and its in the new state then the FateId for that key will be returned.
- * </p>
+ * @return optional w/ the fate id set if seeded and empty optional otherwise
+ */
+ Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp);
+
+ /**
+ * Seeds a transaction with the given repo if its current status is NEW and it is currently
+ * unreserved. Will set the status to SUBMITTED. Will set autoCleanup if true. Will set the
+ * creation time.
*
- * @throws IllegalStateException when there is an unexpected collision. This can occur if two key
- * hash to the same FateId or if a random FateId already exists.
+ * @return true if seeded and false otherwise
*/
- Optional<FateTxStore<T>> createAndReserve(FateKey fateKey);
+ boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp);
Review Comment:
Looks good. I also like the new @return description for these methods indicating result may not be entirely accurate in case of failure
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "kevinrr888 (via GitHub)" <gi...@apache.org>.
kevinrr888 commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1871807750
##########
test/src/main/java/org/apache/accumulo/test/fate/FateStoreIT.java:
##########
@@ -332,14 +336,16 @@ protected void testCreateWithKeyDuplicate(FateStore<TestEnv> store, ServerContex
// A second call to createAndReserve() should just return an empty optional
// since it's already in reserved and in progress
Review Comment:
This comment should be updated or deleted
##########
core/src/main/java/org/apache/accumulo/core/fate/user/FateMutator.java:
##########
@@ -33,6 +33,29 @@ public interface FateMutator<T> {
FateMutator<T> putCreateTime(long ctime);
+ /**
+ * Requires that nothing exists for this fate mutation.
+ */
+ FateMutator<T> requireAbsent();
+
+ /**
+ * Require that the transaction status is one of the given statuses. If no statuses are provided,
+ * require that the status column is absent.
+ *
+ * @param statuses The statuses to check against.
+ */
+ FateMutator<T> requireStatus(TStatus... statuses);
Review Comment:
oh interesting I guess this wasn't in the interface before
##########
core/src/main/java/org/apache/accumulo/core/fate/user/FateMutator.java:
##########
@@ -33,6 +33,29 @@ public interface FateMutator<T> {
FateMutator<T> putCreateTime(long ctime);
+ /**
+ * Requires that nothing exists for this fate mutation.
+ */
+ FateMutator<T> requireAbsent();
+
+ /**
+ * Require that the transaction status is one of the given statuses. If no statuses are provided,
+ * require that the status column is absent.
+ *
+ * @param statuses The statuses to check against.
+ */
+ FateMutator<T> requireStatus(TStatus... statuses);
+
+ /**
+ * Require the transaction has not reservation.
Review Comment:
```suggestion
* Require the transaction has no reservation.
```
##########
core/src/main/java/org/apache/accumulo/core/fate/AbstractFateStore.java:
##########
@@ -402,6 +407,12 @@ public FateId getID() {
public interface FateIdGenerator {
FateId fromTypeAndKey(FateInstanceType instanceType, FateKey fateKey);
+
+ FateId newRandomId(FateInstanceType instanceType);
Review Comment:
I like this, this is a more fitting location
##########
core/src/main/java/org/apache/accumulo/core/fate/Fate.java:
##########
@@ -403,55 +401,14 @@ public FateId startTransaction() {
public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
boolean autoCleanUp, String goalMessage) {
-
- Optional<FateTxStore<T>> optTxStore = store.createAndReserve(fateKey);
-
- return optTxStore.map(txStore -> {
- var fateId = txStore.getID();
- try {
- Preconditions.checkState(txStore.getStatus() == NEW);
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
- return fateId;
- });
- }
-
- private void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
- String goalMessage, FateTxStore<T> txStore) {
- if (txStore.top() == null) {
- try {
- log.info("Seeding {} {}", fateId, goalMessage);
- txStore.push(repo);
- } catch (StackOverflowException e) {
- // this should not happen
- throw new IllegalStateException(e);
- }
- }
-
- if (autoCleanUp) {
- txStore.setTransactionInfo(TxInfo.AUTO_CLEAN, autoCleanUp);
- }
-
- txStore.setTransactionInfo(TxInfo.TX_NAME, txName);
-
- txStore.setStatus(SUBMITTED);
+ return store.seedTransaction(txName, fateKey, repo, autoCleanUp);
Review Comment:
The goal message seems to be lost here. I think before it was just used in a log message. Should probably keep this message
##########
core/src/main/java/org/apache/accumulo/core/fate/Fate.java:
##########
@@ -403,55 +401,14 @@ public FateId startTransaction() {
public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
boolean autoCleanUp, String goalMessage) {
-
- Optional<FateTxStore<T>> optTxStore = store.createAndReserve(fateKey);
-
- return optTxStore.map(txStore -> {
- var fateId = txStore.getID();
- try {
- Preconditions.checkState(txStore.getStatus() == NEW);
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
- return fateId;
- });
- }
-
- private void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
- String goalMessage, FateTxStore<T> txStore) {
- if (txStore.top() == null) {
- try {
- log.info("Seeding {} {}", fateId, goalMessage);
- txStore.push(repo);
- } catch (StackOverflowException e) {
- // this should not happen
- throw new IllegalStateException(e);
- }
- }
-
- if (autoCleanUp) {
- txStore.setTransactionInfo(TxInfo.AUTO_CLEAN, autoCleanUp);
- }
-
- txStore.setTransactionInfo(TxInfo.TX_NAME, txName);
-
- txStore.setStatus(SUBMITTED);
+ return store.seedTransaction(txName, fateKey, repo, autoCleanUp);
}
// start work in the transaction.. it is safe to call this
// multiple times for a transaction... but it will only seed once
public void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
String goalMessage) {
- FateTxStore<T> txStore = store.reserve(fateId);
- try {
- if (txStore.getStatus() == NEW) {
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- }
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
-
+ store.seedTransaction(txName, fateId, repo, autoCleanUp);
Review Comment:
Same goal message comment
##########
core/src/main/java/org/apache/accumulo/core/fate/FateStore.java:
##########
@@ -50,19 +50,22 @@ public interface FateStore<T> extends ReadOnlyFateStore<T> {
FateId create();
/**
- * Creates and reserves a transaction using the given key. If something is already running for the
- * given key, then Optional.empty() will be returned. When this returns a non-empty id, it will be
- * in the new state.
+ * Seeds a transaction with the given repo if it does not exists. Will set the status to
+ * SUBMITTED. Will set the fate key. Will set autoCleanup if true. Will set the creation time.
*
- * <p>
- * In the case where a process dies in the middle of a call to this. If later, another call is
- * made with the same key and its in the new state then the FateId for that key will be returned.
- * </p>
+ * @return optional w/ the fate id set if seeded and empty optional otherwise
+ */
+ Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp);
+
+ /**
+ * Seeds a transaction with the given repo if its current status is NEW and it is currently
+ * unreserved. Will set the status to SUBMITTED. Will set autoCleanup if true. Will set the
+ * creation time.
*
- * @throws IllegalStateException when there is an unexpected collision. This can occur if two key
- * hash to the same FateId or if a random FateId already exists.
+ * @return true if seeded and false otherwise
*/
- Optional<FateTxStore<T>> createAndReserve(FateKey fateKey);
+ boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp);
Review Comment:
Should also add that it will set the txName to these descriptions.
##########
core/src/main/java/org/apache/accumulo/core/fate/user/UserFateStore.java:
##########
@@ -123,104 +123,54 @@ public FateId create() {
}
public FateId getFateId() {
- return FateId.from(fateInstanceType, UUID.randomUUID());
+ return fateIdGenerator.newRandomId(type());
}
@Override
- public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
- final var reservation = FateReservation.from(lockID, UUID.randomUUID());
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
final var fateId = fateIdGenerator.fromTypeAndKey(type(), fateKey);
- Optional<FateTxStore<T>> txStore = Optional.empty();
- int maxAttempts = 5;
- FateMutator.Status status = null;
-
- // Only need to retry if it is UNKNOWN
- for (int attempt = 0; attempt < maxAttempts; attempt++) {
- status = newMutator(fateId).requireStatus().putStatus(TStatus.NEW).putKey(fateKey)
- .putReservedTx(reservation).putCreateTime(System.currentTimeMillis()).tryMutate();
- if (status != FateMutator.Status.UNKNOWN) {
- break;
- }
- UtilWaitThread.sleep(100);
+ Supplier<FateMutator<T>> mutatorFactory = () -> newMutator(fateId).requireAbsent()
+ .putKey(fateKey).putCreateTime(System.currentTimeMillis());
+ if (seedTransaction(mutatorFactory, fateKey + " " + fateId, txName, repo, autoCleanUp)) {
+ return Optional.of(fateId);
+ } else {
+ return Optional.empty();
}
+ }
- switch (status) {
- case ACCEPTED:
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- break;
- case REJECTED:
- // If the status is REJECTED, we need to check what about the mutation was REJECTED:
- // 1) Possible something like the following occurred:
- // the first attempt was UNKNOWN but written, the next attempt would be rejected
- // We return the FateTxStore in this case.
- // 2) If there is a collision with existing fate id, throw error
- // 3) If the fate id is already reserved, return an empty optional
- // 4) If the fate id is still NEW/unseeded and unreserved, we can try to reserve it
- try (Scanner scanner = context.createScanner(tableName, Authorizations.EMPTY)) {
- scanner.setRange(getRow(fateId));
- scanner.fetchColumn(TxColumnFamily.STATUS_COLUMN.getColumnFamily(),
- TxColumnFamily.STATUS_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.TX_KEY_COLUMN.getColumnFamily(),
- TxColumnFamily.TX_KEY_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.RESERVATION_COLUMN.getColumnFamily(),
- TxColumnFamily.RESERVATION_COLUMN.getColumnQualifier());
- TStatus statusSeen = TStatus.UNKNOWN;
- Optional<FateKey> fateKeySeen = Optional.empty();
- Optional<FateReservation> reservationSeen = Optional.empty();
-
- for (Entry<Key,Value> entry : scanner) {
- Text colf = entry.getKey().getColumnFamily();
- Text colq = entry.getKey().getColumnQualifier();
- Value val = entry.getValue();
-
- switch (colq.toString()) {
- case TxColumnFamily.STATUS:
- statusSeen = TStatus.valueOf(val.toString());
- break;
- case TxColumnFamily.TX_KEY:
- fateKeySeen = Optional.of(FateKey.deserialize(val.get()));
- break;
- case TxColumnFamily.RESERVATION:
- reservationSeen = Optional.of(FateReservation.deserialize(val.get()));
- break;
- default:
- throw new IllegalStateException("Unexpected column seen: " + colf + ":" + colq);
- }
- }
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ Supplier<FateMutator<T>> mutatorFactory =
+ () -> newMutator(fateId).requireStatus(TStatus.NEW).requireUnreserved().requireAbsentKey();
+ return seedTransaction(mutatorFactory, fateId.canonical(), txName, repo, autoCleanUp);
+ }
- if (statusSeen == TStatus.NEW) {
- verifyFateKey(fateId, fateKeySeen, fateKey);
- // This will be the case if the mutation status is REJECTED but the mutation was written
- if (reservationSeen.isPresent() && reservationSeen.orElseThrow().equals(reservation)) {
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- } else if (reservationSeen.isEmpty()) {
- // NEW/unseeded transaction and not reserved, so we can allow it to be reserved
- // we tryReserve() since another thread may have reserved it since the scan
- txStore = tryReserve(fateId);
- // the status was known before reserving to be NEW,
- // however it could change so check after reserving to avoid race conditions.
- var statusAfterReserve =
- txStore.map(ReadOnlyFateTxStore::getStatus).orElse(TStatus.UNKNOWN);
- if (statusAfterReserve != TStatus.NEW) {
- txStore.ifPresent(txs -> txs.unreserve(Duration.ZERO));
- txStore = Optional.empty();
- }
- }
- } else {
- log.trace(
- "fate id {} tstatus {} fate key {} is reserved {} "
- + "has already been seeded with work (non-NEW status)",
- fateId, statusSeen, fateKeySeen.orElse(null), reservationSeen.isPresent());
- }
- } catch (TableNotFoundException e) {
- throw new IllegalStateException(tableName + " not found!", e);
- }
- break;
- default:
- throw new IllegalStateException("Unknown or unexpected status " + status);
+ private boolean seedTransaction(Supplier<FateMutator<T>> mutatorFactory, String logId,
+ String txName, Repo<T> repo, boolean autoCleanUp) {
+ int maxAttempts = 5;
+ for (int attempt = 0; attempt < maxAttempts; attempt++) {
+ var mutator = mutatorFactory.get();
+ mutator =
+ mutator.putName(serializeTxInfo(txName)).putRepo(1, repo).putStatus(TStatus.SUBMITTED);
+ if (autoCleanUp) {
+ mutator = mutator.putAutoClean(serializeTxInfo(autoCleanUp));
+ }
+ var status = mutator.tryMutate();
Review Comment:
Logic for final mutator before tryMutate looks good to me for both seeding with and without a FateKey
##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/MetaFateStore.java:
##########
@@ -161,6 +163,52 @@ public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
}
}
+ @Override
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
+ return createAndReserve(fateKey).map(txStore -> {
+ try {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return txStore.getID();
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ });
+ }
+
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ return tryReserve(fateId).map(txStore -> {
+ try {
+ if (txStore.getStatus() == NEW) {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return true;
+ }
+ return false;
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ }).orElseThrow();
Review Comment:
why does this throw and not return false in the case it can't be reserved?
##########
core/src/main/java/org/apache/accumulo/core/fate/user/UserFateStore.java:
##########
@@ -123,104 +123,54 @@ public FateId create() {
}
public FateId getFateId() {
- return FateId.from(fateInstanceType, UUID.randomUUID());
+ return fateIdGenerator.newRandomId(type());
}
@Override
- public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
- final var reservation = FateReservation.from(lockID, UUID.randomUUID());
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
final var fateId = fateIdGenerator.fromTypeAndKey(type(), fateKey);
- Optional<FateTxStore<T>> txStore = Optional.empty();
- int maxAttempts = 5;
- FateMutator.Status status = null;
-
- // Only need to retry if it is UNKNOWN
- for (int attempt = 0; attempt < maxAttempts; attempt++) {
- status = newMutator(fateId).requireStatus().putStatus(TStatus.NEW).putKey(fateKey)
- .putReservedTx(reservation).putCreateTime(System.currentTimeMillis()).tryMutate();
- if (status != FateMutator.Status.UNKNOWN) {
- break;
- }
- UtilWaitThread.sleep(100);
+ Supplier<FateMutator<T>> mutatorFactory = () -> newMutator(fateId).requireAbsent()
+ .putKey(fateKey).putCreateTime(System.currentTimeMillis());
+ if (seedTransaction(mutatorFactory, fateKey + " " + fateId, txName, repo, autoCleanUp)) {
+ return Optional.of(fateId);
+ } else {
+ return Optional.empty();
}
+ }
- switch (status) {
- case ACCEPTED:
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- break;
- case REJECTED:
- // If the status is REJECTED, we need to check what about the mutation was REJECTED:
- // 1) Possible something like the following occurred:
- // the first attempt was UNKNOWN but written, the next attempt would be rejected
- // We return the FateTxStore in this case.
- // 2) If there is a collision with existing fate id, throw error
- // 3) If the fate id is already reserved, return an empty optional
- // 4) If the fate id is still NEW/unseeded and unreserved, we can try to reserve it
- try (Scanner scanner = context.createScanner(tableName, Authorizations.EMPTY)) {
- scanner.setRange(getRow(fateId));
- scanner.fetchColumn(TxColumnFamily.STATUS_COLUMN.getColumnFamily(),
- TxColumnFamily.STATUS_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.TX_KEY_COLUMN.getColumnFamily(),
- TxColumnFamily.TX_KEY_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.RESERVATION_COLUMN.getColumnFamily(),
- TxColumnFamily.RESERVATION_COLUMN.getColumnQualifier());
- TStatus statusSeen = TStatus.UNKNOWN;
- Optional<FateKey> fateKeySeen = Optional.empty();
- Optional<FateReservation> reservationSeen = Optional.empty();
-
- for (Entry<Key,Value> entry : scanner) {
- Text colf = entry.getKey().getColumnFamily();
- Text colq = entry.getKey().getColumnQualifier();
- Value val = entry.getValue();
-
- switch (colq.toString()) {
- case TxColumnFamily.STATUS:
- statusSeen = TStatus.valueOf(val.toString());
- break;
- case TxColumnFamily.TX_KEY:
- fateKeySeen = Optional.of(FateKey.deserialize(val.get()));
- break;
- case TxColumnFamily.RESERVATION:
- reservationSeen = Optional.of(FateReservation.deserialize(val.get()));
- break;
- default:
- throw new IllegalStateException("Unexpected column seen: " + colf + ":" + colq);
- }
- }
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ Supplier<FateMutator<T>> mutatorFactory =
+ () -> newMutator(fateId).requireStatus(TStatus.NEW).requireUnreserved().requireAbsentKey();
+ return seedTransaction(mutatorFactory, fateId.canonical(), txName, repo, autoCleanUp);
+ }
- if (statusSeen == TStatus.NEW) {
- verifyFateKey(fateId, fateKeySeen, fateKey);
- // This will be the case if the mutation status is REJECTED but the mutation was written
- if (reservationSeen.isPresent() && reservationSeen.orElseThrow().equals(reservation)) {
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- } else if (reservationSeen.isEmpty()) {
- // NEW/unseeded transaction and not reserved, so we can allow it to be reserved
- // we tryReserve() since another thread may have reserved it since the scan
- txStore = tryReserve(fateId);
- // the status was known before reserving to be NEW,
- // however it could change so check after reserving to avoid race conditions.
- var statusAfterReserve =
- txStore.map(ReadOnlyFateTxStore::getStatus).orElse(TStatus.UNKNOWN);
- if (statusAfterReserve != TStatus.NEW) {
- txStore.ifPresent(txs -> txs.unreserve(Duration.ZERO));
- txStore = Optional.empty();
- }
- }
- } else {
- log.trace(
- "fate id {} tstatus {} fate key {} is reserved {} "
- + "has already been seeded with work (non-NEW status)",
- fateId, statusSeen, fateKeySeen.orElse(null), reservationSeen.isPresent());
- }
- } catch (TableNotFoundException e) {
- throw new IllegalStateException(tableName + " not found!", e);
- }
- break;
- default:
- throw new IllegalStateException("Unknown or unexpected status " + status);
+ private boolean seedTransaction(Supplier<FateMutator<T>> mutatorFactory, String logId,
+ String txName, Repo<T> repo, boolean autoCleanUp) {
+ int maxAttempts = 5;
+ for (int attempt = 0; attempt < maxAttempts; attempt++) {
+ var mutator = mutatorFactory.get();
+ mutator =
+ mutator.putName(serializeTxInfo(txName)).putRepo(1, repo).putStatus(TStatus.SUBMITTED);
+ if (autoCleanUp) {
+ mutator = mutator.putAutoClean(serializeTxInfo(autoCleanUp));
+ }
+ var status = mutator.tryMutate();
+ if (status == FateMutator.Status.ACCEPTED) {
+ // signal to the super class that a new fate transaction was seeded and is ready to run
+ seededTx();
+ return true;
+ } else if (status == FateMutator.Status.REJECTED) {
Review Comment:
I'm wondering about the following case:
The first attempt is actually written but returns a status of UNKNOWN. Then, any subsequent attempts will return REJECTED causing seedTransaction to return that it failed/false.
This was something that was previously handled
##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/MetaFateStore.java:
##########
@@ -161,6 +163,52 @@ public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
}
}
+ @Override
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
+ return createAndReserve(fateKey).map(txStore -> {
+ try {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return txStore.getID();
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ });
+ }
+
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ return tryReserve(fateId).map(txStore -> {
+ try {
+ if (txStore.getStatus() == NEW) {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return true;
+ }
+ return false;
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ }).orElseThrow();
+ }
+
+ protected void seedTransaction(String txName, Repo<T> repo, boolean autoCleanUp,
Review Comment:
any reason this isn't private?
##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/MetaFateStore.java:
##########
@@ -112,8 +115,7 @@ public FateId create() {
}
}
- @Override
- public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
+ private Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
Review Comment:
I like that Fate.java just calls store.seedTransaction and createAndReserve is private now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "kevinrr888 (via GitHub)" <gi...@apache.org>.
kevinrr888 commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1876861938
##########
core/src/main/java/org/apache/accumulo/core/fate/FateStore.java:
##########
@@ -50,19 +50,22 @@ public interface FateStore<T> extends ReadOnlyFateStore<T> {
FateId create();
/**
- * Creates and reserves a transaction using the given key. If something is already running for the
- * given key, then Optional.empty() will be returned. When this returns a non-empty id, it will be
- * in the new state.
+ * Seeds a transaction with the given repo if it does not exists. Will set the status to
+ * SUBMITTED. Will set the fate key. Will set autoCleanup if true. Will set the creation time.
*
- * <p>
- * In the case where a process dies in the middle of a call to this. If later, another call is
- * made with the same key and its in the new state then the FateId for that key will be returned.
- * </p>
+ * @return optional w/ the fate id set if seeded and empty optional otherwise
+ */
+ Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp);
+
+ /**
+ * Seeds a transaction with the given repo if its current status is NEW and it is currently
+ * unreserved. Will set the status to SUBMITTED. Will set autoCleanup if true. Will set the
+ * creation time.
*
- * @throws IllegalStateException when there is an unexpected collision. This can occur if two key
- * hash to the same FateId or if a random FateId already exists.
+ * @return true if seeded and false otherwise
*/
- Optional<FateTxStore<T>> createAndReserve(FateKey fateKey);
+ boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp);
Review Comment:
Looks good. I also like the new @ return description for these methods indicating result may not be entirely accurate in case of failure
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872372069
##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/MetaFateStore.java:
##########
@@ -161,6 +163,52 @@ public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
}
}
+ @Override
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
+ return createAndReserve(fateKey).map(txStore -> {
+ try {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return txStore.getID();
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ });
+ }
+
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ return tryReserve(fateId).map(txStore -> {
+ try {
+ if (txStore.getStatus() == NEW) {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return true;
+ }
+ return false;
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ }).orElseThrow();
Review Comment:
fixed in e47089c
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872312987
##########
core/src/main/java/org/apache/accumulo/core/fate/user/FateMutator.java:
##########
@@ -33,6 +33,29 @@ public interface FateMutator<T> {
FateMutator<T> putCreateTime(long ctime);
+ /**
+ * Requires that nothing exists for this fate mutation.
+ */
+ FateMutator<T> requireAbsent();
+
+ /**
+ * Require that the transaction status is one of the given statuses. If no statuses are provided,
+ * require that the status column is absent.
+ *
+ * @param statuses The statuses to check against.
+ */
+ FateMutator<T> requireStatus(TStatus... statuses);
Review Comment:
When working on this I was trying to call the method and my IDE was not finding it but I knew it was supposed to be there. Finally figured out it was only on the impl.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "kevinrr888 (via GitHub)" <gi...@apache.org>.
kevinrr888 commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1873948600
##########
core/src/main/java/org/apache/accumulo/core/fate/Fate.java:
##########
@@ -403,55 +401,14 @@ public FateId startTransaction() {
public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
boolean autoCleanUp, String goalMessage) {
-
- Optional<FateTxStore<T>> optTxStore = store.createAndReserve(fateKey);
-
- return optTxStore.map(txStore -> {
- var fateId = txStore.getID();
- try {
- Preconditions.checkState(txStore.getStatus() == NEW);
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
- return fateId;
- });
- }
-
- private void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
- String goalMessage, FateTxStore<T> txStore) {
- if (txStore.top() == null) {
- try {
- log.info("Seeding {} {}", fateId, goalMessage);
- txStore.push(repo);
- } catch (StackOverflowException e) {
- // this should not happen
- throw new IllegalStateException(e);
- }
- }
-
- if (autoCleanUp) {
- txStore.setTransactionInfo(TxInfo.AUTO_CLEAN, autoCleanUp);
- }
-
- txStore.setTransactionInfo(TxInfo.TX_NAME, txName);
-
- txStore.setStatus(SUBMITTED);
+ return store.seedTransaction(txName, fateKey, repo, autoCleanUp);
Review Comment:
Just making sure, did you choose to get rid of the goalMessage here since the same message will be logged after this call in both use cases (a system initiated split or a commit compaction). If so, that seems good to me. I was just confused at first why it was removed here then noticed both use cases have a log after.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner merged PR #5122:
URL: https://github.com/apache/accumulo/pull/5122
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872372733
##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/MetaFateStore.java:
##########
@@ -161,6 +163,52 @@ public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
}
}
+ @Override
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
+ return createAndReserve(fateKey).map(txStore -> {
+ try {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return txStore.getID();
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ });
+ }
+
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ return tryReserve(fateId).map(txStore -> {
+ try {
+ if (txStore.getStatus() == NEW) {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return true;
+ }
+ return false;
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ }).orElseThrow();
+ }
+
+ protected void seedTransaction(String txName, Repo<T> repo, boolean autoCleanUp,
Review Comment:
fixed in https://github.com/apache/accumulo/commit/e47089c5d9e0efa0007c88b535e9bb3f55b4a44a
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1874041378
##########
test/src/main/java/org/apache/accumulo/test/fate/FateStoreIT.java:
##########
@@ -332,14 +336,16 @@ protected void testCreateWithKeyDuplicate(FateStore<TestEnv> store, ServerContex
// A second call to createAndReserve() should just return an empty optional
// since it's already in reserved and in progress
Review Comment:
Updated in [7110fd7](https://github.com/apache/accumulo/pull/5122/commits/7110fd7e7da4c8b48b8d386c9bf36a78a1820edc)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872329882
##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/MetaFateStore.java:
##########
@@ -161,6 +163,52 @@ public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
}
}
+ @Override
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
+ return createAndReserve(fateKey).map(txStore -> {
+ try {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return txStore.getID();
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ });
+ }
+
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ return tryReserve(fateId).map(txStore -> {
+ try {
+ if (txStore.getStatus() == NEW) {
+ seedTransaction(txName, repo, autoCleanUp, txStore);
+ return true;
+ }
+ return false;
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ }).orElseThrow();
Review Comment:
It should not do that, I will fix that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1874040053
##########
core/src/main/java/org/apache/accumulo/core/fate/FateStore.java:
##########
@@ -50,19 +50,22 @@ public interface FateStore<T> extends ReadOnlyFateStore<T> {
FateId create();
/**
- * Creates and reserves a transaction using the given key. If something is already running for the
- * given key, then Optional.empty() will be returned. When this returns a non-empty id, it will be
- * in the new state.
+ * Seeds a transaction with the given repo if it does not exists. Will set the status to
+ * SUBMITTED. Will set the fate key. Will set autoCleanup if true. Will set the creation time.
*
- * <p>
- * In the case where a process dies in the middle of a call to this. If later, another call is
- * made with the same key and its in the new state then the FateId for that key will be returned.
- * </p>
+ * @return optional w/ the fate id set if seeded and empty optional otherwise
+ */
+ Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp);
+
+ /**
+ * Seeds a transaction with the given repo if its current status is NEW and it is currently
+ * unreserved. Will set the status to SUBMITTED. Will set autoCleanup if true. Will set the
+ * creation time.
*
- * @throws IllegalStateException when there is an unexpected collision. This can occur if two key
- * hash to the same FateId or if a random FateId already exists.
+ * @return true if seeded and false otherwise
*/
- Optional<FateTxStore<T>> createAndReserve(FateKey fateKey);
+ boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp);
Review Comment:
updated in 7110fd7
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1874085627
##########
core/src/main/java/org/apache/accumulo/core/fate/user/UserFateStore.java:
##########
@@ -123,104 +123,54 @@ public FateId create() {
}
public FateId getFateId() {
- return FateId.from(fateInstanceType, UUID.randomUUID());
+ return fateIdGenerator.newRandomId(type());
}
@Override
- public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
- final var reservation = FateReservation.from(lockID, UUID.randomUUID());
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
final var fateId = fateIdGenerator.fromTypeAndKey(type(), fateKey);
- Optional<FateTxStore<T>> txStore = Optional.empty();
- int maxAttempts = 5;
- FateMutator.Status status = null;
-
- // Only need to retry if it is UNKNOWN
- for (int attempt = 0; attempt < maxAttempts; attempt++) {
- status = newMutator(fateId).requireStatus().putStatus(TStatus.NEW).putKey(fateKey)
- .putReservedTx(reservation).putCreateTime(System.currentTimeMillis()).tryMutate();
- if (status != FateMutator.Status.UNKNOWN) {
- break;
- }
- UtilWaitThread.sleep(100);
+ Supplier<FateMutator<T>> mutatorFactory = () -> newMutator(fateId).requireAbsent()
+ .putKey(fateKey).putCreateTime(System.currentTimeMillis());
+ if (seedTransaction(mutatorFactory, fateKey + " " + fateId, txName, repo, autoCleanUp)) {
+ return Optional.of(fateId);
+ } else {
+ return Optional.empty();
}
+ }
- switch (status) {
- case ACCEPTED:
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- break;
- case REJECTED:
- // If the status is REJECTED, we need to check what about the mutation was REJECTED:
- // 1) Possible something like the following occurred:
- // the first attempt was UNKNOWN but written, the next attempt would be rejected
- // We return the FateTxStore in this case.
- // 2) If there is a collision with existing fate id, throw error
- // 3) If the fate id is already reserved, return an empty optional
- // 4) If the fate id is still NEW/unseeded and unreserved, we can try to reserve it
- try (Scanner scanner = context.createScanner(tableName, Authorizations.EMPTY)) {
- scanner.setRange(getRow(fateId));
- scanner.fetchColumn(TxColumnFamily.STATUS_COLUMN.getColumnFamily(),
- TxColumnFamily.STATUS_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.TX_KEY_COLUMN.getColumnFamily(),
- TxColumnFamily.TX_KEY_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.RESERVATION_COLUMN.getColumnFamily(),
- TxColumnFamily.RESERVATION_COLUMN.getColumnQualifier());
- TStatus statusSeen = TStatus.UNKNOWN;
- Optional<FateKey> fateKeySeen = Optional.empty();
- Optional<FateReservation> reservationSeen = Optional.empty();
-
- for (Entry<Key,Value> entry : scanner) {
- Text colf = entry.getKey().getColumnFamily();
- Text colq = entry.getKey().getColumnQualifier();
- Value val = entry.getValue();
-
- switch (colq.toString()) {
- case TxColumnFamily.STATUS:
- statusSeen = TStatus.valueOf(val.toString());
- break;
- case TxColumnFamily.TX_KEY:
- fateKeySeen = Optional.of(FateKey.deserialize(val.get()));
- break;
- case TxColumnFamily.RESERVATION:
- reservationSeen = Optional.of(FateReservation.deserialize(val.get()));
- break;
- default:
- throw new IllegalStateException("Unexpected column seen: " + colf + ":" + colq);
- }
- }
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ Supplier<FateMutator<T>> mutatorFactory =
+ () -> newMutator(fateId).requireStatus(TStatus.NEW).requireUnreserved().requireAbsentKey();
+ return seedTransaction(mutatorFactory, fateId.canonical(), txName, repo, autoCleanUp);
+ }
- if (statusSeen == TStatus.NEW) {
- verifyFateKey(fateId, fateKeySeen, fateKey);
- // This will be the case if the mutation status is REJECTED but the mutation was written
- if (reservationSeen.isPresent() && reservationSeen.orElseThrow().equals(reservation)) {
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- } else if (reservationSeen.isEmpty()) {
- // NEW/unseeded transaction and not reserved, so we can allow it to be reserved
- // we tryReserve() since another thread may have reserved it since the scan
- txStore = tryReserve(fateId);
- // the status was known before reserving to be NEW,
- // however it could change so check after reserving to avoid race conditions.
- var statusAfterReserve =
- txStore.map(ReadOnlyFateTxStore::getStatus).orElse(TStatus.UNKNOWN);
- if (statusAfterReserve != TStatus.NEW) {
- txStore.ifPresent(txs -> txs.unreserve(Duration.ZERO));
- txStore = Optional.empty();
- }
- }
- } else {
- log.trace(
- "fate id {} tstatus {} fate key {} is reserved {} "
- + "has already been seeded with work (non-NEW status)",
- fateId, statusSeen, fateKeySeen.orElse(null), reservationSeen.isPresent());
- }
- } catch (TableNotFoundException e) {
- throw new IllegalStateException(tableName + " not found!", e);
- }
- break;
- default:
- throw new IllegalStateException("Unknown or unexpected status " + status);
+ private boolean seedTransaction(Supplier<FateMutator<T>> mutatorFactory, String logId,
+ String txName, Repo<T> repo, boolean autoCleanUp) {
+ int maxAttempts = 5;
+ for (int attempt = 0; attempt < maxAttempts; attempt++) {
+ var mutator = mutatorFactory.get();
+ mutator =
+ mutator.putName(serializeTxInfo(txName)).putRepo(1, repo).putStatus(TStatus.SUBMITTED);
+ if (autoCleanUp) {
+ mutator = mutator.putAutoClean(serializeTxInfo(autoCleanUp));
+ }
+ var status = mutator.tryMutate();
+ if (status == FateMutator.Status.ACCEPTED) {
+ // signal to the super class that a new fate transaction was seeded and is ready to run
+ seededTx();
+ return true;
+ } else if (status == FateMutator.Status.REJECTED) {
Review Comment:
Tried to handle the unknown case and realized its impossible to determine what happened in this case. Prior to these changes a reservation was acquired and that has unique uuid which can be used to determine if the reservation was acquired when unknown is seen. Now that this code is using a single conditional mutation, no reservation is required. The reservation is only required for updates that happen over multiple conditional mutations.
So since there is no way to know what happened, I adjusted the logging and code to reflect this in 89b70da
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1874100633
##########
core/src/main/java/org/apache/accumulo/core/fate/Fate.java:
##########
@@ -403,55 +401,14 @@ public FateId startTransaction() {
public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
boolean autoCleanUp, String goalMessage) {
-
- Optional<FateTxStore<T>> optTxStore = store.createAndReserve(fateKey);
-
- return optTxStore.map(txStore -> {
- var fateId = txStore.getID();
- try {
- Preconditions.checkState(txStore.getStatus() == NEW);
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
- return fateId;
- });
- }
-
- private void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
- String goalMessage, FateTxStore<T> txStore) {
- if (txStore.top() == null) {
- try {
- log.info("Seeding {} {}", fateId, goalMessage);
- txStore.push(repo);
- } catch (StackOverflowException e) {
- // this should not happen
- throw new IllegalStateException(e);
- }
- }
-
- if (autoCleanUp) {
- txStore.setTransactionInfo(TxInfo.AUTO_CLEAN, autoCleanUp);
- }
-
- txStore.setTransactionInfo(TxInfo.TX_NAME, txName);
-
- txStore.setStatus(SUBMITTED);
+ return store.seedTransaction(txName, fateKey, repo, autoCleanUp);
Review Comment:
> Just making sure, did you choose to get rid of the goalMessage here since the same message will be logged after this call in both use cases (a system initiated split or a commit compaction). If so, that seems good to me. I was just confused at first why it was removed here then noticed both use cases have a log after.
Yes that is why I removed it. Then those log messages were removed in 89b70da. Looking into this a bit more I think the fateKey contains all the information that was in the goal. The FateLogger class nicely logs the fateKey and other info already, so the information is still available in the logs. Improved fate logger in 42f8b4d after looking into this comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "kevinrr888 (via GitHub)" <gi...@apache.org>.
kevinrr888 commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1876742706
##########
test/src/main/java/org/apache/accumulo/test/fate/FateStoreIT.java:
##########
@@ -430,26 +447,191 @@ protected void testCollisionWithRandomFateId(FateStore<TestEnv> store, ServerCon
new KeyExtent(TableId.of(getUniqueNames(1)[0]), new Text("zzz"), new Text("aaa"));
FateKey fateKey = FateKey.forSplit(ke);
- FateTxStore<TestEnv> txStore = store.createAndReserve(fateKey).orElseThrow();
- FateId fateId = txStore.getID();
+ var fateId = store.seedTransaction("TEST", fateKey, new TestRepo(), true).orElseThrow();
// After createAndReserve a fate transaction using a key we can simulate a collision with
// a random FateId by deleting the key out of Fate and calling createAndReserve again to
// verify it detects the key is missing. Then we can continue and see if we can still use
// the existing transaction.
Review Comment:
```suggestion
// After seeding a fate transaction using a key we can simulate a collision with
// a random FateId by deleting the key out of Fate and calling seed again to
// verify it detects the key is missing. Then we can continue and see if we can still use
// the existing transaction.
```
Also grepped to ensure this was the last mention of createAndReserve in comments
##########
test/src/main/java/org/apache/accumulo/test/fate/FateStoreIT.java:
##########
@@ -430,26 +447,191 @@ protected void testCollisionWithRandomFateId(FateStore<TestEnv> store, ServerCon
new KeyExtent(TableId.of(getUniqueNames(1)[0]), new Text("zzz"), new Text("aaa"));
FateKey fateKey = FateKey.forSplit(ke);
- FateTxStore<TestEnv> txStore = store.createAndReserve(fateKey).orElseThrow();
- FateId fateId = txStore.getID();
+ var fateId = store.seedTransaction("TEST", fateKey, new TestRepo(), true).orElseThrow();
// After createAndReserve a fate transaction using a key we can simulate a collision with
// a random FateId by deleting the key out of Fate and calling createAndReserve again to
// verify it detects the key is missing. Then we can continue and see if we can still use
// the existing transaction.
deleteKey(fateId, sctx);
- var e = assertThrows(IllegalStateException.class, () -> store.createAndReserve(fateKey));
- assertEquals("fate key is missing from fate id " + fateId, e.getMessage());
+ assertTrue(store.seedTransaction("TEST", fateKey, new TestRepo(), true).isEmpty());
+ var txStore = store.reserve(fateId);
// We should still be able to use the existing transaction
try {
assertTrue(txStore.timeCreated() > 0);
+ assertEquals(TStatus.SUBMITTED, txStore.getStatus());
+ } finally {
+ txStore.delete();
+ txStore.unreserve(Duration.ZERO);
+ }
+ }
+
+ public static final UUID DUPLICATE_UUID = UUID.randomUUID();
+
+ public static final List<UUID> UUIDS = List.of(DUPLICATE_UUID, DUPLICATE_UUID, UUID.randomUUID());
+
+ @Test
+ public void testCreate() throws Exception {
+ AtomicInteger index = new AtomicInteger(0);
+ executeTest(this::testCreate, AbstractFateStore.DEFAULT_MAX_DEFERRED,
+ new AbstractFateStore.FateIdGenerator() {
+ @Override
+ public FateId fromTypeAndKey(FateInstanceType instanceType, FateKey fateKey) {
+ return FateId.from(instanceType,
+ UUID.nameUUIDFromBytes("testing uuid".getBytes(UTF_8)));
+ }
+
+ @Override
+ public FateId newRandomId(FateInstanceType instanceType) {
+ return FateId.from(instanceType, UUIDS.get(index.getAndIncrement() % UUIDS.size()));
+ }
+ });
+ }
+
+ protected void testCreate(FateStore<TestEnv> store, ServerContext sctx) throws Exception {
+
+ var fateId1 = store.create();
+ assertEquals(UUIDS.get(0), fateId1.getTxUUID());
+
+ // This UUIDS[1] should collide with UUIDS[0] and then the code should retry and end up UUIDS[2]
+ var fateId2 = store.create();
+ assertEquals(UUIDS.get(2), fateId2.getTxUUID());
+
+ for (var fateId : List.of(fateId1, fateId2)) {
+ var txStore = store.reserve(fateId);
+ try {
+ assertEquals(TStatus.NEW, txStore.getStatus());
+ assertTrue(txStore.timeCreated() > 0);
+ assertNull(txStore.top());
+ assertTrue(txStore.getKey().isEmpty());
+ assertEquals(fateId, txStore.getID());
+ assertTrue(txStore.getStack().isEmpty());
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+ }
+
+ assertEquals(Set.of(fateId1, fateId2),
+ store.list().map(FateIdStatus::getFateId).collect(Collectors.toSet()));
+
+ var txStore = store.reserve(fateId2);
+ try {
+ txStore.delete();
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+
+ assertEquals(Set.of(fateId1),
+ store.list().map(FateIdStatus::getFateId).collect(Collectors.toSet()));
+
+ txStore = store.reserve(fateId1);
+ try {
+ txStore.setStatus(TStatus.SUBMITTED);
+ txStore.setStatus(TStatus.IN_PROGRESS);
+ txStore.push(new TestRepo());
+ } finally {
+ txStore.unreserve(Duration.ZERO);
+ }
+
+ assertEquals(Set.of(fateId1),
+ store.list().map(FateIdStatus::getFateId).collect(Collectors.toSet()));
+
+ // should collide again with the first fate id and go to the second
+ fateId2 = store.create();
+ assertEquals(UUIDS.get(2), fateId2.getTxUUID());
+
+ assertEquals(Set.of(fateId1, fateId2),
+ store.list().map(FateIdStatus::getFateId).collect(Collectors.toSet()));
+
+ // ensure fateId1 was not altered in anyway by creating fateid2 when it collided
+ txStore = store.reserve(fateId1);
+ try {
+ assertEquals(TStatus.IN_PROGRESS, txStore.getStatus());
+ txStore.forceDelete();
Review Comment:
could also check top() here before deleting
##########
core/src/main/java/org/apache/accumulo/core/fate/user/UserFateStore.java:
##########
@@ -123,104 +123,54 @@ public FateId create() {
}
public FateId getFateId() {
- return FateId.from(fateInstanceType, UUID.randomUUID());
+ return fateIdGenerator.newRandomId(type());
}
@Override
- public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
- final var reservation = FateReservation.from(lockID, UUID.randomUUID());
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
final var fateId = fateIdGenerator.fromTypeAndKey(type(), fateKey);
- Optional<FateTxStore<T>> txStore = Optional.empty();
- int maxAttempts = 5;
- FateMutator.Status status = null;
-
- // Only need to retry if it is UNKNOWN
- for (int attempt = 0; attempt < maxAttempts; attempt++) {
- status = newMutator(fateId).requireStatus().putStatus(TStatus.NEW).putKey(fateKey)
- .putReservedTx(reservation).putCreateTime(System.currentTimeMillis()).tryMutate();
- if (status != FateMutator.Status.UNKNOWN) {
- break;
- }
- UtilWaitThread.sleep(100);
+ Supplier<FateMutator<T>> mutatorFactory = () -> newMutator(fateId).requireAbsent()
+ .putKey(fateKey).putCreateTime(System.currentTimeMillis());
+ if (seedTransaction(mutatorFactory, fateKey + " " + fateId, txName, repo, autoCleanUp)) {
+ return Optional.of(fateId);
+ } else {
+ return Optional.empty();
}
+ }
- switch (status) {
- case ACCEPTED:
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- break;
- case REJECTED:
- // If the status is REJECTED, we need to check what about the mutation was REJECTED:
- // 1) Possible something like the following occurred:
- // the first attempt was UNKNOWN but written, the next attempt would be rejected
- // We return the FateTxStore in this case.
- // 2) If there is a collision with existing fate id, throw error
- // 3) If the fate id is already reserved, return an empty optional
- // 4) If the fate id is still NEW/unseeded and unreserved, we can try to reserve it
- try (Scanner scanner = context.createScanner(tableName, Authorizations.EMPTY)) {
- scanner.setRange(getRow(fateId));
- scanner.fetchColumn(TxColumnFamily.STATUS_COLUMN.getColumnFamily(),
- TxColumnFamily.STATUS_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.TX_KEY_COLUMN.getColumnFamily(),
- TxColumnFamily.TX_KEY_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.RESERVATION_COLUMN.getColumnFamily(),
- TxColumnFamily.RESERVATION_COLUMN.getColumnQualifier());
- TStatus statusSeen = TStatus.UNKNOWN;
- Optional<FateKey> fateKeySeen = Optional.empty();
- Optional<FateReservation> reservationSeen = Optional.empty();
-
- for (Entry<Key,Value> entry : scanner) {
- Text colf = entry.getKey().getColumnFamily();
- Text colq = entry.getKey().getColumnQualifier();
- Value val = entry.getValue();
-
- switch (colq.toString()) {
- case TxColumnFamily.STATUS:
- statusSeen = TStatus.valueOf(val.toString());
- break;
- case TxColumnFamily.TX_KEY:
- fateKeySeen = Optional.of(FateKey.deserialize(val.get()));
- break;
- case TxColumnFamily.RESERVATION:
- reservationSeen = Optional.of(FateReservation.deserialize(val.get()));
- break;
- default:
- throw new IllegalStateException("Unexpected column seen: " + colf + ":" + colq);
- }
- }
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ Supplier<FateMutator<T>> mutatorFactory =
+ () -> newMutator(fateId).requireStatus(TStatus.NEW).requireUnreserved().requireAbsentKey();
+ return seedTransaction(mutatorFactory, fateId.canonical(), txName, repo, autoCleanUp);
+ }
- if (statusSeen == TStatus.NEW) {
- verifyFateKey(fateId, fateKeySeen, fateKey);
- // This will be the case if the mutation status is REJECTED but the mutation was written
- if (reservationSeen.isPresent() && reservationSeen.orElseThrow().equals(reservation)) {
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- } else if (reservationSeen.isEmpty()) {
- // NEW/unseeded transaction and not reserved, so we can allow it to be reserved
- // we tryReserve() since another thread may have reserved it since the scan
- txStore = tryReserve(fateId);
- // the status was known before reserving to be NEW,
- // however it could change so check after reserving to avoid race conditions.
- var statusAfterReserve =
- txStore.map(ReadOnlyFateTxStore::getStatus).orElse(TStatus.UNKNOWN);
- if (statusAfterReserve != TStatus.NEW) {
- txStore.ifPresent(txs -> txs.unreserve(Duration.ZERO));
- txStore = Optional.empty();
- }
- }
- } else {
- log.trace(
- "fate id {} tstatus {} fate key {} is reserved {} "
- + "has already been seeded with work (non-NEW status)",
- fateId, statusSeen, fateKeySeen.orElse(null), reservationSeen.isPresent());
- }
- } catch (TableNotFoundException e) {
- throw new IllegalStateException(tableName + " not found!", e);
- }
- break;
- default:
- throw new IllegalStateException("Unknown or unexpected status " + status);
+ private boolean seedTransaction(Supplier<FateMutator<T>> mutatorFactory, String logId,
+ String txName, Repo<T> repo, boolean autoCleanUp) {
+ int maxAttempts = 5;
+ for (int attempt = 0; attempt < maxAttempts; attempt++) {
+ var mutator = mutatorFactory.get();
+ mutator =
+ mutator.putName(serializeTxInfo(txName)).putRepo(1, repo).putStatus(TStatus.SUBMITTED);
+ if (autoCleanUp) {
+ mutator = mutator.putAutoClean(serializeTxInfo(autoCleanUp));
+ }
+ var status = mutator.tryMutate();
+ if (status == FateMutator.Status.ACCEPTED) {
+ // signal to the super class that a new fate transaction was seeded and is ready to run
+ seededTx();
+ return true;
+ } else if (status == FateMutator.Status.REJECTED) {
Review Comment:
Ah, yeah you're right...
The new comment for the UNKNOWN case looks good. The new mention of "*possibly* unable to seed" in FateLogger looks good.
##########
core/src/main/java/org/apache/accumulo/core/fate/Fate.java:
##########
@@ -403,55 +401,14 @@ public FateId startTransaction() {
public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
boolean autoCleanUp, String goalMessage) {
-
- Optional<FateTxStore<T>> optTxStore = store.createAndReserve(fateKey);
-
- return optTxStore.map(txStore -> {
- var fateId = txStore.getID();
- try {
- Preconditions.checkState(txStore.getStatus() == NEW);
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
- return fateId;
- });
- }
-
- private void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
- String goalMessage, FateTxStore<T> txStore) {
- if (txStore.top() == null) {
- try {
- log.info("Seeding {} {}", fateId, goalMessage);
- txStore.push(repo);
- } catch (StackOverflowException e) {
- // this should not happen
- throw new IllegalStateException(e);
- }
- }
-
- if (autoCleanUp) {
- txStore.setTransactionInfo(TxInfo.AUTO_CLEAN, autoCleanUp);
- }
-
- txStore.setTransactionInfo(TxInfo.TX_NAME, txName);
-
- txStore.setStatus(SUBMITTED);
+ return store.seedTransaction(txName, fateKey, repo, autoCleanUp);
Review Comment:
I agree that FateKey contains the same info. Those changes look good.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1874100633
##########
core/src/main/java/org/apache/accumulo/core/fate/Fate.java:
##########
@@ -403,55 +401,14 @@ public FateId startTransaction() {
public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
boolean autoCleanUp, String goalMessage) {
-
- Optional<FateTxStore<T>> optTxStore = store.createAndReserve(fateKey);
-
- return optTxStore.map(txStore -> {
- var fateId = txStore.getID();
- try {
- Preconditions.checkState(txStore.getStatus() == NEW);
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
- return fateId;
- });
- }
-
- private void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
- String goalMessage, FateTxStore<T> txStore) {
- if (txStore.top() == null) {
- try {
- log.info("Seeding {} {}", fateId, goalMessage);
- txStore.push(repo);
- } catch (StackOverflowException e) {
- // this should not happen
- throw new IllegalStateException(e);
- }
- }
-
- if (autoCleanUp) {
- txStore.setTransactionInfo(TxInfo.AUTO_CLEAN, autoCleanUp);
- }
-
- txStore.setTransactionInfo(TxInfo.TX_NAME, txName);
-
- txStore.setStatus(SUBMITTED);
+ return store.seedTransaction(txName, fateKey, repo, autoCleanUp);
Review Comment:
> Just making sure, did you choose to get rid of the goalMessage here since the same message will be logged after this call in both use cases (a system initiated split or a commit compaction). If so, that seems good to me. I was just confused at first why it was removed here then noticed both use cases have a log after.
Yes that is why I removed it. Then those log messages were removed in 89b70da. Looking into this a bit more I think the fateKey contains all the information that was in the goal. The FateLogger class nicely logs the fateKey an other info already, so the information is still available in the logs. Improved fate logger in 42f8b4d after looking into this comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872374636
##########
core/src/main/java/org/apache/accumulo/core/fate/user/UserFateStore.java:
##########
@@ -123,104 +123,54 @@ public FateId create() {
}
public FateId getFateId() {
- return FateId.from(fateInstanceType, UUID.randomUUID());
+ return fateIdGenerator.newRandomId(type());
}
@Override
- public Optional<FateTxStore<T>> createAndReserve(FateKey fateKey) {
- final var reservation = FateReservation.from(lockID, UUID.randomUUID());
+ public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
+ boolean autoCleanUp) {
final var fateId = fateIdGenerator.fromTypeAndKey(type(), fateKey);
- Optional<FateTxStore<T>> txStore = Optional.empty();
- int maxAttempts = 5;
- FateMutator.Status status = null;
-
- // Only need to retry if it is UNKNOWN
- for (int attempt = 0; attempt < maxAttempts; attempt++) {
- status = newMutator(fateId).requireStatus().putStatus(TStatus.NEW).putKey(fateKey)
- .putReservedTx(reservation).putCreateTime(System.currentTimeMillis()).tryMutate();
- if (status != FateMutator.Status.UNKNOWN) {
- break;
- }
- UtilWaitThread.sleep(100);
+ Supplier<FateMutator<T>> mutatorFactory = () -> newMutator(fateId).requireAbsent()
+ .putKey(fateKey).putCreateTime(System.currentTimeMillis());
+ if (seedTransaction(mutatorFactory, fateKey + " " + fateId, txName, repo, autoCleanUp)) {
+ return Optional.of(fateId);
+ } else {
+ return Optional.empty();
}
+ }
- switch (status) {
- case ACCEPTED:
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- break;
- case REJECTED:
- // If the status is REJECTED, we need to check what about the mutation was REJECTED:
- // 1) Possible something like the following occurred:
- // the first attempt was UNKNOWN but written, the next attempt would be rejected
- // We return the FateTxStore in this case.
- // 2) If there is a collision with existing fate id, throw error
- // 3) If the fate id is already reserved, return an empty optional
- // 4) If the fate id is still NEW/unseeded and unreserved, we can try to reserve it
- try (Scanner scanner = context.createScanner(tableName, Authorizations.EMPTY)) {
- scanner.setRange(getRow(fateId));
- scanner.fetchColumn(TxColumnFamily.STATUS_COLUMN.getColumnFamily(),
- TxColumnFamily.STATUS_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.TX_KEY_COLUMN.getColumnFamily(),
- TxColumnFamily.TX_KEY_COLUMN.getColumnQualifier());
- scanner.fetchColumn(TxColumnFamily.RESERVATION_COLUMN.getColumnFamily(),
- TxColumnFamily.RESERVATION_COLUMN.getColumnQualifier());
- TStatus statusSeen = TStatus.UNKNOWN;
- Optional<FateKey> fateKeySeen = Optional.empty();
- Optional<FateReservation> reservationSeen = Optional.empty();
-
- for (Entry<Key,Value> entry : scanner) {
- Text colf = entry.getKey().getColumnFamily();
- Text colq = entry.getKey().getColumnQualifier();
- Value val = entry.getValue();
-
- switch (colq.toString()) {
- case TxColumnFamily.STATUS:
- statusSeen = TStatus.valueOf(val.toString());
- break;
- case TxColumnFamily.TX_KEY:
- fateKeySeen = Optional.of(FateKey.deserialize(val.get()));
- break;
- case TxColumnFamily.RESERVATION:
- reservationSeen = Optional.of(FateReservation.deserialize(val.get()));
- break;
- default:
- throw new IllegalStateException("Unexpected column seen: " + colf + ":" + colq);
- }
- }
+ @Override
+ public boolean seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp) {
+ Supplier<FateMutator<T>> mutatorFactory =
+ () -> newMutator(fateId).requireStatus(TStatus.NEW).requireUnreserved().requireAbsentKey();
+ return seedTransaction(mutatorFactory, fateId.canonical(), txName, repo, autoCleanUp);
+ }
- if (statusSeen == TStatus.NEW) {
- verifyFateKey(fateId, fateKeySeen, fateKey);
- // This will be the case if the mutation status is REJECTED but the mutation was written
- if (reservationSeen.isPresent() && reservationSeen.orElseThrow().equals(reservation)) {
- txStore = Optional.of(new FateTxStoreImpl(fateId, reservation));
- } else if (reservationSeen.isEmpty()) {
- // NEW/unseeded transaction and not reserved, so we can allow it to be reserved
- // we tryReserve() since another thread may have reserved it since the scan
- txStore = tryReserve(fateId);
- // the status was known before reserving to be NEW,
- // however it could change so check after reserving to avoid race conditions.
- var statusAfterReserve =
- txStore.map(ReadOnlyFateTxStore::getStatus).orElse(TStatus.UNKNOWN);
- if (statusAfterReserve != TStatus.NEW) {
- txStore.ifPresent(txs -> txs.unreserve(Duration.ZERO));
- txStore = Optional.empty();
- }
- }
- } else {
- log.trace(
- "fate id {} tstatus {} fate key {} is reserved {} "
- + "has already been seeded with work (non-NEW status)",
- fateId, statusSeen, fateKeySeen.orElse(null), reservationSeen.isPresent());
- }
- } catch (TableNotFoundException e) {
- throw new IllegalStateException(tableName + " not found!", e);
- }
- break;
- default:
- throw new IllegalStateException("Unknown or unexpected status " + status);
+ private boolean seedTransaction(Supplier<FateMutator<T>> mutatorFactory, String logId,
+ String txName, Repo<T> repo, boolean autoCleanUp) {
+ int maxAttempts = 5;
+ for (int attempt = 0; attempt < maxAttempts; attempt++) {
+ var mutator = mutatorFactory.get();
+ mutator =
+ mutator.putName(serializeTxInfo(txName)).putRepo(1, repo).putStatus(TStatus.SUBMITTED);
+ if (autoCleanUp) {
+ mutator = mutator.putAutoClean(serializeTxInfo(autoCleanUp));
+ }
+ var status = mutator.tryMutate();
+ if (status == FateMutator.Status.ACCEPTED) {
+ // signal to the super class that a new fate transaction was seeded and is ready to run
+ seededTx();
+ return true;
+ } else if (status == FateMutator.Status.REJECTED) {
Review Comment:
Looking at this some more I will make it try to determine what happened. Even thought its just logging, having accurate log message is important for debugging. And I like the info provided by the current log messages.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Makes seeding a fate transaction more efficient [accumulo]
Posted by "keith-turner (via GitHub)" <gi...@apache.org>.
keith-turner commented on code in PR #5122:
URL: https://github.com/apache/accumulo/pull/5122#discussion_r1872373545
##########
core/src/main/java/org/apache/accumulo/core/fate/Fate.java:
##########
@@ -403,55 +401,14 @@ public FateId startTransaction() {
public Optional<FateId> seedTransaction(String txName, FateKey fateKey, Repo<T> repo,
boolean autoCleanUp, String goalMessage) {
-
- Optional<FateTxStore<T>> optTxStore = store.createAndReserve(fateKey);
-
- return optTxStore.map(txStore -> {
- var fateId = txStore.getID();
- try {
- Preconditions.checkState(txStore.getStatus() == NEW);
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
- return fateId;
- });
- }
-
- private void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
- String goalMessage, FateTxStore<T> txStore) {
- if (txStore.top() == null) {
- try {
- log.info("Seeding {} {}", fateId, goalMessage);
- txStore.push(repo);
- } catch (StackOverflowException e) {
- // this should not happen
- throw new IllegalStateException(e);
- }
- }
-
- if (autoCleanUp) {
- txStore.setTransactionInfo(TxInfo.AUTO_CLEAN, autoCleanUp);
- }
-
- txStore.setTransactionInfo(TxInfo.TX_NAME, txName);
-
- txStore.setStatus(SUBMITTED);
+ return store.seedTransaction(txName, fateKey, repo, autoCleanUp);
}
// start work in the transaction.. it is safe to call this
// multiple times for a transaction... but it will only seed once
public void seedTransaction(String txName, FateId fateId, Repo<T> repo, boolean autoCleanUp,
String goalMessage) {
- FateTxStore<T> txStore = store.reserve(fateId);
- try {
- if (txStore.getStatus() == NEW) {
- seedTransaction(txName, fateId, repo, autoCleanUp, goalMessage, txStore);
- }
- } finally {
- txStore.unreserve(Duration.ZERO);
- }
-
+ store.seedTransaction(txName, fateId, repo, autoCleanUp);
Review Comment:
fixed in https://github.com/apache/accumulo/commit/e47089c5d9e0efa0007c88b535e9bb3f55b4a44a
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org