This is an automated email from the ASF dual-hosted git repository. dlmarion pushed a commit to branch elasticity in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/elasticity by this push: new 193c010d36 Moved removeUnusedWALEntries to Tablet (#4404) 193c010d36 is described below commit 193c010d36732b3a9a1cd602afad225498b6ac54 Author: Dave Marion <dlmar...@apache.org> AuthorDate: Mon Apr 8 10:58:42 2024 -0400 Moved removeUnusedWALEntries to Tablet (#4404) Moved MetadataTableUtil.removeUnusedWALEntries code to Tablet constructor. Changed logic to use conditional mutations. --- .../accumulo/server/util/MetadataTableUtil.java | 9 ------ .../org/apache/accumulo/tserver/tablet/Tablet.java | 35 +++++++++++++++------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java b/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java index f87805d092..e5db26344f 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/MetadataTableUtil.java @@ -31,7 +31,6 @@ import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -244,14 +243,6 @@ public class MetadataTableUtil { return new Pair<>(result, sizes); } - public static void removeUnusedWALEntries(ServerContext context, KeyExtent extent, - final Collection<LogEntry> entries, ServiceLock zooLock) { - TabletMutator tablet = context.getAmple().mutateTablet(extent); - entries.forEach(tablet::deleteWal); - tablet.putZooLock(context.getZooKeeperRoot(), zooLock); - tablet.mutate(); - } - private static Mutation createCloneMutation(TableId srcTableId, TableId tableId, Map<Key,Value> tablet) { diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java index a0f8b95857..414fedd105 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/tablet/Tablet.java @@ -59,12 +59,17 @@ import org.apache.accumulo.core.dataImpl.KeyExtent; import org.apache.accumulo.core.file.FilePrefix; import org.apache.accumulo.core.iterators.SortedKeyValueIterator; import org.apache.accumulo.core.iteratorsImpl.system.SourceSwitchingIterator; +import org.apache.accumulo.core.lock.ServiceLock; import org.apache.accumulo.core.logging.TabletLogger; import org.apache.accumulo.core.manager.state.tables.TableState; import org.apache.accumulo.core.metadata.AccumuloTable; import org.apache.accumulo.core.metadata.ReferencedTabletFile; import org.apache.accumulo.core.metadata.StoredTabletFile; import org.apache.accumulo.core.metadata.schema.Ample; +import org.apache.accumulo.core.metadata.schema.Ample.ConditionalResult; +import org.apache.accumulo.core.metadata.schema.Ample.ConditionalResult.Status; +import org.apache.accumulo.core.metadata.schema.Ample.ConditionalTabletMutator; +import org.apache.accumulo.core.metadata.schema.Ample.ConditionalTabletsMutator; import org.apache.accumulo.core.metadata.schema.DataFileValue; import org.apache.accumulo.core.metadata.schema.TabletMetadata; import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType; @@ -85,7 +90,6 @@ import org.apache.accumulo.server.problems.ProblemType; import org.apache.accumulo.server.tablets.ConditionCheckerContext.ConditionChecker; import org.apache.accumulo.server.tablets.TabletNameGenerator; import org.apache.accumulo.server.tablets.TabletTime; -import org.apache.accumulo.server.util.MetadataTableUtil; import org.apache.accumulo.tserver.InMemoryMap; import org.apache.accumulo.tserver.MinorCompactionReason; import org.apache.accumulo.tserver.TabletServer; @@ -126,7 +130,6 @@ public class Tablet extends TabletBase { private final TabletTime tabletTime; - private Location lastLocation = null; private final Set<Path> checkedTabletDirs = new ConcurrentSkipListSet<>(); private final AtomicLong dataSourceDeletions = new AtomicLong(0); @@ -231,10 +234,6 @@ public class Tablet extends TabletBase { this.tabletServer = tabletServer; this.tabletResources = trm; this.latestMetadata = metadata; - - // TODO look into this.. also last could be null - this.lastLocation = metadata.getLast(); - this.tabletTime = TabletTime.getInstance(metadata.getTime()); this.logId = tabletServer.createLogId(); @@ -277,10 +276,25 @@ public class Tablet extends TabletBase { commitSession.updateMaxCommittedTime(tabletTime.getTime()); if (entriesUsedOnTablet.get() == 0) { - log.debug("No replayed mutations applied, removing unused entries for {}", extent); - // ELASTICITY_TODO use conditional mutation for update - MetadataTableUtil.removeUnusedWALEntries(getTabletServer().getContext(), extent, - logEntries, tabletServer.getLock()); + log.debug("No replayed mutations applied, removing unused walog entries for {}", extent); + + final ServiceLock zooLock = tabletServer.getLock(); + final Location expectedLocation = Location.future(this.tabletServer.getTabletSession()); + try (ConditionalTabletsMutator mutator = + getContext().getAmple().conditionallyMutateTablets()) { + ConditionalTabletMutator mut = mutator.mutateTablet(extent).requireAbsentOperation() + .requireLocation(expectedLocation) + .putZooLock(getContext().getZooKeeperRoot(), zooLock); + logEntries.forEach(mut::deleteWal); + mut.submit(tabletMetadata -> tabletMetadata.getLogs().isEmpty()); + + ConditionalResult res = mutator.process().get(extent); + if (res.getStatus() == Status.REJECTED) { + throw new IllegalStateException( + "Unable to remove logs in metadata for extent: " + extent); + } + } + // intentionally not rereading metadata here because walogs are only used in the // constructor logEntries.clear(); @@ -1578,7 +1592,6 @@ public class Tablet extends TabletBase { // the tabletMetadata. Scans sync on the tablet also, so they can not be in this code // block at the same time. - lastLocation = null; tabletMemory.finishedMinC(); // the files and in memory map changed, incrementing this will cause scans to switch data