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

Base64 encode compaction input file list #5229

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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 @@ -18,10 +18,12 @@
*/
package org.apache.accumulo.core.metadata.schema;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import static org.apache.accumulo.core.util.LazySingletons.GSON;

import java.util.Base64;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand All @@ -32,6 +34,9 @@
import org.apache.accumulo.core.spi.compaction.CompactionKind;
import org.apache.accumulo.core.spi.compaction.CompactorGroupId;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class CompactionMetadata {

private final Set<StoredTabletFile> jobFiles;
Expand Down Expand Up @@ -96,7 +101,7 @@ public FateId getFateId() {
// This class is used to serialize and deserialize this class using GSon. Any changes to this
// class must consider persisted data.
private static class GSonData {
List<String> inputs;
String inputs;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wonder if we could make this inputs field a JsonElement like this SO post describes to avoid base64 and avoid escaping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That could be an alternative, but instead of the json object example from the post (which looks like a map), we would need to use a json array of strings.

String tmp;
String compactor;
String kind;
Expand All @@ -107,23 +112,35 @@ private static class GSonData {
}

public String toJson() {
GSonData jData = new GSonData();

jData.inputs = jobFiles.stream().map(StoredTabletFile::getMetadata).collect(toList());
final Gson gson = GSON.get();

List<String> inputFiles =
jobFiles.stream().map(StoredTabletFile::getMetadata).collect(toList());
String inputFilesJson = gson.toJson(inputFiles);

final GSonData jData = new GSonData();
jData.inputs = Base64.getEncoder().encodeToString(inputFilesJson.getBytes(UTF_8));
jData.tmp = compactTmpName.insert().getMetadata();
jData.compactor = compactorId;
jData.kind = kind.name();
jData.groupId = cgid.toString();
jData.priority = priority;
jData.propDels = propagateDeletes;
jData.fateId = fateId == null ? null : fateId.canonical();
return GSON.get().toJson(jData);
return gson.toJson(jData);
}

public static CompactionMetadata fromJson(String json) {
GSonData jData = GSON.get().fromJson(json, GSonData.class);
final Gson gson = GSON.get();

GSonData jData = gson.fromJson(json, GSonData.class);

byte[] inputFilesDecoded = Base64.getDecoder().decode(jData.inputs);
List<String> inputFiles = gson.fromJson(new String(inputFilesDecoded, UTF_8),
new TypeToken<List<String>>() {}.getType());

return new CompactionMetadata(jData.inputs.stream().map(StoredTabletFile::new).collect(toSet()),
return new CompactionMetadata(inputFiles.stream().map(StoredTabletFile::new).collect(toSet()),
StoredTabletFile.of(jData.tmp).getTabletFile(), jData.compactor,
CompactionKind.valueOf(jData.kind), jData.priority, CompactorGroupId.of(jData.groupId),
jData.propDels, jData.fateId == null ? null : FateId.from(jData.fateId));
Expand Down
Loading