Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoids holding tablet metadata for queued compactions #5247

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -55,6 +57,8 @@
import org.apache.accumulo.core.util.Pair;
import org.apache.accumulo.core.util.TextUtil;
import org.apache.hadoop.io.BinaryComparable;
import org.apache.hadoop.io.DataInputBuffer;
import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.io.Text;

/**
Expand Down Expand Up @@ -560,4 +564,26 @@ public String obscured() {
return Base64.getEncoder().encodeToString(digester.digest());
}

public String toBase64() {
DataOutputBuffer buffer = new DataOutputBuffer();
try {
writeTo(buffer);
} catch (IOException e) {
throw new UncheckedIOException(e);
}

return Base64.getEncoder().encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));
}

public static KeyExtent fromBase64(String encoded) {
byte[] data = Base64.getDecoder().decode(encoded);
DataInputBuffer buffer = new DataInputBuffer();
buffer.reset(data, data.length);
try {
return KeyExtent.readFrom(buffer);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.accumulo.core.metadata.TServerInstance;
import org.apache.accumulo.core.metadata.TabletFile;
import org.apache.accumulo.core.metadata.schema.ExternalCompactionId;
import org.apache.accumulo.core.metadata.schema.TabletMetadata;
import org.apache.accumulo.core.spi.compaction.CompactionJob;
import org.apache.accumulo.core.spi.compaction.CompactionKind;
import org.apache.accumulo.core.tabletserver.log.LogEntry;
Expand Down Expand Up @@ -147,20 +146,18 @@ public static void selected(FateId fateId, KeyExtent extent,
Collections2.transform(inputs, StoredTabletFile::toMinimalString));
}

public static void compacting(TabletMetadata tabletMetadata, ExternalCompactionId cid,
public static void compacting(KeyExtent extent, FateId selectedFateId, ExternalCompactionId cid,
String compactorAddress, CompactionJob job) {
if (fileLog.isDebugEnabled()) {
if (job.getKind() == CompactionKind.USER) {
var fateId = tabletMetadata.getSelectedFiles().getFateId();
fileLog.debug(
"Compacting {} driver:{} id:{} group:{} compactor:{} priority:{} size:{} kind:{} files:{}",
tabletMetadata.getExtent(), fateId, cid, job.getGroup(), compactorAddress,
job.getPriority(), getSize(job.getFiles()), job.getKind(),
asMinimalString(job.getFiles()));
extent, selectedFateId, cid, job.getGroup(), compactorAddress, job.getPriority(),
getSize(job.getFiles()), job.getKind(), asMinimalString(job.getFiles()));
} else {
fileLog.debug(
"Compacting {} id:{} group:{} compactor:{} priority:{} size:{} kind:{} files:{}",
tabletMetadata.getExtent(), cid, job.getGroup(), compactorAddress, job.getPriority(),
extent, cid, job.getGroup(), compactorAddress, job.getPriority(),
getSize(job.getFiles()), job.getKind(), asMinimalString(job.getFiles()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,10 @@ ConditionalTabletMutator requireSame(TabletMetadata tabletMetadata, ColumnType t
ConditionalTabletMutator requireAbsentLoaded(Set<ReferencedTabletFile> files);

/**
* Requires the given set of files are not currently involved in any running compactions.
* This check will run atomically on the server side and must pass in order for the tablet to be
* updated.
*/
ConditionalTabletMutator requireNotCompacting(Set<StoredTabletFile> files);
ConditionalTabletMutator requireCheckSuccess(TabletMetadataCheck check);

/**
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.accumulo.core.metadata.schema;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

/**
* This interface facilitates atomic checks of tablet metadata prior to updating tablet metadata.
* The way it is intended to be used is the following.
* <ol>
* <li>On the client side a TabletMetadataCheck object is created and passed to Ample</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if there is any good way to specifically validate that an implementation can be correctly serialized by gson, especially because we've configured our gson to not allow unsafe usage (so we require a default constructor and not using final etc). I'm guessing the only way is just to to make sure there are tests that use the new check in a conditional mutation and verify it works which is probably fine as we should be writing tests anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think making sure the impl is tested is the best option for that.

* <li>Ample uses Gson to serialize the object, so it must not reference anything that can not
* serialize. Also it should not reference big things like server context or the Manager, it should
* only reference a small amount of data needed for the check.
* <li>On the tablet server side, as part of conditional mutation processing, this class is
* recreated and the {@link #canUpdate(TabletMetadata)} method is called and if it returns true the
* conditional mutation will go through.</li>
* </ol>
*
* <p>
* Implementations are expected to have a no arg constructor.
* </p>
*
*/
public interface TabletMetadataCheck {

Set<TabletMetadata.ColumnType> ALL_COLUMNS =
Collections.unmodifiableSet(EnumSet.noneOf(TabletMetadata.ColumnType.class));

boolean canUpdate(TabletMetadata tabletMetadata);

/**
* Determines what tablet metadata columns are read on the server side. Return the empty set to
* read all tablet metadata columns.
*/
default Set<TabletMetadata.ColumnType> columnsToRead() {
return ALL_COLUMNS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import org.apache.accumulo.core.client.admin.compaction.CompactableFile;
Expand All @@ -40,22 +39,13 @@ public class CompactionJobImpl implements CompactionJob {
private final CompactorGroupId group;
private final Set<CompactableFile> files;
private final CompactionKind kind;
// Tracks if a job selected all the tablet's files that existed at the time the job was created.
private final Optional<Boolean> jobSelectedAll;

/**
*
* @param jobSelectedAll This parameters only needs to be non-empty for job objects that are used
* to start compaction. After a job is running, its not used. So when a job object is
* recreated for a running external compaction this parameter can be empty.
*/
public CompactionJobImpl(short priority, CompactorGroupId group,
Collection<CompactableFile> files, CompactionKind kind, Optional<Boolean> jobSelectedAll) {
Collection<CompactableFile> files, CompactionKind kind) {
this.priority = priority;
this.group = Objects.requireNonNull(group);
this.files = Set.copyOf(files);
this.kind = Objects.requireNonNull(kind);
this.jobSelectedAll = Objects.requireNonNull(jobSelectedAll);
}

@Override
Expand Down Expand Up @@ -92,10 +82,6 @@ public int hashCode() {
return Objects.hash(priority, group, files, kind);
}

public boolean selectedAll() {
return jobSelectedAll.orElseThrow();
}

@Override
public boolean equals(Object o) {
if (o instanceof CompactionJobImpl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.apache.accumulo.core.client.admin.compaction.CompactableFile;
Expand Down Expand Up @@ -80,8 +79,7 @@ public Builder addJob(short priority, CompactorGroupId group,

seenFiles.addAll(filesSet);

jobs.add(new CompactionJobImpl(priority, group, filesSet, kind,
Optional.of(filesSet.equals(allFiles))));
jobs.add(new CompactionJobImpl(priority, group, filesSet, kind));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -632,7 +631,7 @@ public void testMaxTabletFilesNoCompaction() {
// that a compaction is not planned
all = createCFs(1_000, 2, 2, 2, 2, 2, 2, 2);
var job = new CompactionJobImpl((short) 1, CompactorGroupId.of("ee1"), createCFs("F1", "1000"),
CompactionKind.SYSTEM, Optional.of(false));
CompactionKind.SYSTEM);
params = createPlanningParams(all, all, Set.of(job), 3, CompactionKind.SYSTEM, conf);
plan = planner.makePlan(params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;

import org.apache.accumulo.core.client.admin.compaction.CompactableFile;
import org.apache.accumulo.core.clientImpl.Namespace;
Expand All @@ -60,10 +59,9 @@ public CompactionJob createJob(CompactionKind kind, String tablet, int numFiles,
files.add(CompactableFile
.create(URI.create("hdfs://foonn/accumulo/tables/5/" + tablet + "/" + i + ".rf"), 4, 4));
}
return new CompactionJobImpl(
CompactionJobPrioritizer.createPriority(Namespace.DEFAULT.id(), TableId.of("5"), kind,
totalFiles, numFiles, totalFiles * 2),
CompactorGroupId.of("test"), files, kind, Optional.of(false));
return new CompactionJobImpl(CompactionJobPrioritizer.createPriority(Namespace.DEFAULT.id(),
TableId.of("5"), kind, totalFiles, numFiles, totalFiles * 2), CompactorGroupId.of("test"),
files, kind);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -285,7 +284,7 @@ public Collection<CompactionJob> getRunningCompactions() {
Collection<CompactableFile> files = ecMeta.getJobFiles().stream()
.map(f -> new CompactableFileImpl(f, allFiles2.get(f))).collect(Collectors.toList());
CompactionJob job = new CompactionJobImpl(ecMeta.getPriority(),
ecMeta.getCompactionGroupId(), files, ecMeta.getKind(), Optional.empty());
ecMeta.getCompactionGroupId(), files, ecMeta.getKind());
return job;
}).collect(Collectors.toUnmodifiableList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.apache.accumulo.core.classloader.ClassLoaderUtil;
Expand Down Expand Up @@ -211,7 +212,7 @@ public Optional<SortedKeyValueIterator<Key,Value>> getSample(CompactableFile cf,

public static Map<String,String> computeOverrides(Optional<CompactionConfig> compactionConfig,
ServerContext context, KeyExtent extent, Set<CompactableFile> inputFiles,
Set<CompactableFile> selectedFiles) {
Supplier<Set<CompactableFile>> selectedFiles) {

if (compactionConfig.isPresent()
&& !UserCompactionUtils.isDefault(compactionConfig.orElseThrow().getConfigurer())) {
Expand All @@ -234,7 +235,8 @@ public static Map<String,String> computeOverrides(Optional<CompactionConfig> com
}

public static Map<String,String> computeOverrides(ServerContext context, KeyExtent extent,
Set<CompactableFile> inputFiles, Set<CompactableFile> selectedFiles, PluginConfig cfg) {
Set<CompactableFile> inputFiles, Supplier<Set<CompactableFile>> selectedFiles,
PluginConfig cfg) {

CompactionConfigurer configurer = newInstance(context.getTableConfiguration(extent.tableId()),
cfg.getClassName(), CompactionConfigurer.class);
Expand Down Expand Up @@ -266,7 +268,7 @@ public Collection<CompactableFile> getInputFiles() {

@Override
public Set<CompactableFile> getSelectedFiles() {
return selectedFiles;
return selectedFiles.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
import static java.util.stream.Collectors.toUnmodifiableMap;
import static java.util.stream.Collectors.toUnmodifiableSet;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -49,8 +45,6 @@
import org.apache.accumulo.core.util.time.SteadyTime;
import org.apache.accumulo.server.manager.LiveTServerSet;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DataInputBuffer;
import org.apache.hadoop.io.DataOutputBuffer;

import com.google.common.base.Suppliers;
import com.google.gson.Gson;
Expand Down Expand Up @@ -120,7 +114,7 @@ private TabletManagementParameters(JsonData jdata) {
this.serversToShutdown =
jdata.serversToShutdown.stream().map(TServerInstance::new).collect(toUnmodifiableSet());
this.migrations = jdata.migrations.entrySet().stream()
.collect(toUnmodifiableMap(entry -> JsonData.strToExtent(entry.getKey()),
.collect(toUnmodifiableMap(entry -> KeyExtent.fromBase64(entry.getKey()),
entry -> new TServerInstance(entry.getValue())));
this.level = jdata.level;
this.compactionHints = makeImmutable(jdata.compactionHints.entrySet().stream()
Expand Down Expand Up @@ -226,30 +220,6 @@ private static class JsonData {
Map<URI,URI> volumeReplacements;
long steadyTime;

private static String toString(KeyExtent extent) {
DataOutputBuffer buffer = new DataOutputBuffer();
try {
extent.writeTo(buffer);
} catch (IOException e) {
throw new UncheckedIOException(e);
}

return Base64.getEncoder()
.encodeToString(Arrays.copyOf(buffer.getData(), buffer.getLength()));

}

private static KeyExtent strToExtent(String kes) {
byte[] data = Base64.getDecoder().decode(kes);
DataInputBuffer buffer = new DataInputBuffer();
buffer.reset(data, data.length);
try {
return KeyExtent.readFrom(buffer);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

// Gson requires private constructor
@SuppressWarnings("unused")
private JsonData() {}
Expand All @@ -262,8 +232,9 @@ private JsonData() {}
.collect(toList());
serversToShutdown = params.serversToShutdown.stream().map(TServerInstance::getHostPortSession)
.collect(toList());
migrations = params.migrations.entrySet().stream().collect(
toMap(entry -> toString(entry.getKey()), entry -> entry.getValue().getHostPortSession()));
migrations =
params.migrations.entrySet().stream().collect(toMap(entry -> entry.getKey().toBase64(),
entry -> entry.getValue().getHostPortSession()));
level = params.level;
tserverGroups = params.getGroupedTServers().entrySet().stream()
.collect(toMap(Map.Entry::getKey, entry -> entry.getValue().stream()
Expand Down
Loading
Loading