Skip to content

Commit

Permalink
re apache#3724: tablet transaction log
Browse files Browse the repository at this point in the history
* Created an enumeration for the table.operation.log.recovery.action's
* Completed the implementation of the metadata/memory updates
  • Loading branch information
ivakegg committed Aug 27, 2023
1 parent d3afd17 commit 6f23198
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 17 deletions.
26 changes: 26 additions & 0 deletions core/src/main/java/org/apache/accumulo/core/conf/LogSync.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.conf;

/**
* Constants to be used for the DatafileTransactionLog
*/
public enum LogSync {
log, logsync, metasync, memsync
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ public enum PropertyType {
"One of 'none', 'flush', or 'compact'."),

DATAFILE_RECOVERY_ACTION("datafile_recovery_action",
in(true, null, "log", "logsync", "metasync", "memsync"),
"One of 'log', 'logsync', 'metasync', 'memsync',"),

in(true, null, LogSync.log.name(), LogSync.logsync.name(), LogSync.metasync.name(),
LogSync.memsync.name()),
"One of '" + LogSync.log + "', '" + LogSync.logsync + "', '" + LogSync.metasync + "', '"
+ LogSync.memsync + "'"),
LAST_LOCATION_MODE("last_location_mode", in(true, null, "assignment", "compaction"),
"Defines how to update the last location. One of 'assignment', or 'compaction'."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ public static void replaceDatafiles(ServerContext context, KeyExtent extent,
tablet.mutate();
}

public static void replaceDatafiles(ServerContext context, KeyExtent extent,
Set<StoredTabletFile> datafilesToDelete, Map<StoredTabletFile,DataFileValue> datafilesToAdd) {

context.getAmple().putGcCandidates(extent.tableId(), datafilesToDelete);

TabletMutator tablet = context.getAmple().mutateTablet(extent);

datafilesToDelete.forEach(tablet::deleteFile);
datafilesToAdd.forEach(tablet::putFile);

tablet.mutate();
}

/**
* Update tablet file data from flush. Returns a StoredTabletFile if there are data entries.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.accumulo.core.conf.LogSync;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.dataImpl.KeyExtent;
import org.apache.accumulo.core.logging.TabletLogger;
Expand Down Expand Up @@ -594,7 +595,8 @@ public MetadataUpdateCount getUpdateCount() {
* @param context The server context
*/
public void handleMetadataDiff(ServerContext context) {
String action = tablet.getTableConfiguration().get(Property.TABLE_OPERATION_LOG_RECOVERY);
LogSync action =
LogSync.valueOf(tablet.getTableConfiguration().get(Property.TABLE_OPERATION_LOG_RECOVERY));
synchronized (tablet) {
// always log the operation log regardless of the requested action
log.error("Operation log: " + tabletLog.dumpLog());
Expand All @@ -618,44 +620,61 @@ public void handleMetadataDiff(ServerContext context) {
"Resetting operation log " + expected + " with metadata and memory " + memory);
tabletLog.reset(memory);
}
} else if (!action.equals("log")) {
if (action.equals("logsync")) {
} else if (!action.equals(LogSync.log)) {
if (action.equals(LogSync.logsync)) {
if (expected.equals(memory)) {
action = "memsync";
action = LogSync.memsync;
} else if (expected.equals(metadata)) {
action = "metasync";
action = LogSync.metasync;
} else {
log.error("Not synching files because the operation log " + expected
+ " does not agree with metadata " + metadata + " or memory " + memory);
+ " does not agree with metadata " + metadata + " nor memory " + memory);
}
}

if (action.equals("metasync")) {
if (action.equals(LogSync.metasync)) {
if (!expected.equals(metadata)) {
log.error("Not synching memory because the operation log " + expected
+ " does not agree with metadata " + metadata);
} else {
resetMemoryWithMetadata();
resetMemoryWithMetadata(tabletMeta.getFilesMap());
}
} else if (action.equals("memsync")) {
} else if (action.equals(LogSync.memsync)) {
if (!expected.equals(memory)) {
log.error("Not synching metadata because the operation log " + expected
+ " does not agree with memory " + memory);
} else {
resetMetadataWithMemory();
resetMetadataWithMemory(metadata, datafileSizes);
}
}
}
}
}
}

private void resetMemoryWithMetadata() {
// TODO
private void resetMemoryWithMetadata(Map<StoredTabletFile,DataFileValue> metadata) {
// increment start count before metadata update AND updating in memory map of files
metadataUpdateCount.updateAndGet(MetadataUpdateCount::incrementStart);
try {
datafileSizes.clear();
datafileSizes.putAll(metadata);
} finally {
// increment start count before metadata update AND updating in memory map of files
metadataUpdateCount.updateAndGet(MetadataUpdateCount::incrementFinish);
}
}

private void resetMetadataWithMemory() {
// TODO
private void resetMetadataWithMemory(Set<StoredTabletFile> metadata,
Map<StoredTabletFile,DataFileValue> memory) {
// increment start count before metadata update AND updating in memory map of files
metadataUpdateCount.updateAndGet(MetadataUpdateCount::incrementStart);
try {
ManagerMetadataUtil.replaceDatafiles(tablet.getContext(), tablet.getExtent(), metadata,
memory);
} finally {
// increment start count before metadata update AND updating in memory map of files
metadataUpdateCount.updateAndGet(MetadataUpdateCount::incrementFinish);
}
}

}

0 comments on commit 6f23198

Please sign in to comment.