keith-turner commented on code in PR #3863: URL: https://github.com/apache/accumulo/pull/3863#discussion_r1364481719
########## 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: The refresh metadata is inside the if, so the behavior is the same. That closing brace goes with the try. Its not easy to see here, I thought it was always calling refresh until I went to an ide to fix 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-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org