dlmarion commented on code in PR #3863: URL: https://github.com/apache/accumulo/pull/3863#discussion_r1364414366
########## server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java: ########## @@ -445,18 +441,38 @@ public void flush(long tableFlushID) { refreshLock.lock(); try { // if multiple threads were allowed to update this outside of a sync block, then it would - // be - // a race condition - // ELASTICITY_TODO use conditional mutations - MetadataTableUtil.updateTabletFlushID(extent, tableFlushID, context, - getTabletServer().getLock()); - // It is important the the refresh lock is held for the update above and the refresh below - // to avoid race conditions. - refreshMetadata(RefreshPurpose.FLUSH_ID_UPDATE); + // be a race condition + + var lastTabletMetadata = getMetadata(); + + // Check flush id while holding refresh lock to prevent race condition with other threads + // in tablet reading and writing the tablets metadata. + if (lastTabletMetadata.getFlushId().orElse(-1) < tableFlushID) { + try (var tabletsMutator = getContext().getAmple().conditionallyMutateTablets()) { + var tablet = tabletsMutator.mutateTablet(extent) + .requireLocation(Location.current(tabletServer.getTabletSession())) + .requireSame(lastTabletMetadata, ColumnType.PREV_ROW, ColumnType.FLUSH_ID); + + tablet.putFlushId(tableFlushID); + tablet.putZooLock(context.getZooKeeperRoot(), getTabletServer().getLock()); + tablet + .submit(tabletMetadata -> tabletMetadata.getFlushId().orElse(-1) == tableFlushID); + + var result = tabletsMutator.process().get(extent); + + if (result.getStatus() != Ample.ConditionalResult.Status.ACCEPTED) { + throw new IllegalStateException("Failed to update flush id " + extent + " " + + tabletServer.getTabletSession() + " " + tableFlushID); + } + } Review Comment: should there be an `else` here that just `return`'s? That's what the prior code did, it returned without refreshing the metadata. -- 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-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org