Skip to content

Commit

Permalink
Globally Unique FATE Transaction Ids - Part 4 (#4258)
Browse files Browse the repository at this point in the history
This addresses several previously deferred changes for issue #4044.
Changes:
- ZooReservation now uses FateId (used in Utils)
- TabletOperationId now uses FateId
- TExternalCompactionJob now uses FateId
- VolumeManager and VolumeManagerImpl now use FateId
- Utils.getLock() lockData now uses the full FateId
- TabletRefresher now uses FateId
- Classes which used the above classes updated
- Several test changes to reflect new changes
- Deferred a couple of changes (in Compactor and CompactionCoordinator) (need pull/4247 merged first)
  • Loading branch information
kevinrr888 authored Feb 16, 2024
1 parent da7b3b0 commit a3ec20e
Show file tree
Hide file tree
Showing 33 changed files with 191 additions and 152 deletions.
23 changes: 22 additions & 1 deletion core/src/main/java/org/apache/accumulo/core/fate/FateId.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.apache.accumulo.core.data.AbstractId;
import org.apache.accumulo.core.manager.thrift.TFateId;
import org.apache.accumulo.core.manager.thrift.TFateInstanceType;
import org.apache.accumulo.core.util.FastFormat;

/**
Expand Down Expand Up @@ -107,7 +108,7 @@ public static FateId from(String fateIdStr) {
* @param fateIdStr the string representation of the FateId
* @return true if the string is a valid FateId, false otherwise
*/
public static boolean isFormattedTid(String fateIdStr) {
public static boolean isFateId(String fateIdStr) {
return FATEID_PATTERN.matcher(fateIdStr).matches();
}

Expand All @@ -133,6 +134,26 @@ public static FateId fromThrift(TFateId tFateId) {
return new FateId(PREFIX + type + ":" + formatTid(tid));
}

/**
*
* @return the TFateId equivalent of the FateId
*/
public TFateId toThrift() {
TFateInstanceType thriftType;
FateInstanceType type = getType();
switch (type) {
case USER:
thriftType = TFateInstanceType.USER;
break;
case META:
thriftType = TFateInstanceType.META;
break;
default:
throw new IllegalArgumentException("Invalid FateInstanceType: " + type);
}
return new TFateId(thriftType, getTid());
}

/**
* Returns the hex string equivalent of the tid
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static java.nio.charset.StandardCharsets.UTF_8;

import org.apache.accumulo.core.fate.FateId;
import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeMissingPolicy;
import org.apache.zookeeper.KeeperException;
Expand All @@ -29,15 +30,14 @@

public class ZooReservation {

public static boolean attempt(ZooReaderWriter zk, String path, String reservationID,
String debugInfo) throws KeeperException, InterruptedException {
if (reservationID.contains(":")) {
throw new IllegalArgumentException();
}
private static final String DELIMITER = "-";

public static boolean attempt(ZooReaderWriter zk, String path, FateId fateId, String debugInfo)
throws KeeperException, InterruptedException {

while (true) {
try {
zk.putPersistentData(path, (reservationID + ":" + debugInfo).getBytes(UTF_8),
zk.putPersistentData(path, (fateId.canonical() + DELIMITER + debugInfo).getBytes(UTF_8),
NodeExistsPolicy.FAIL);
return true;
} catch (NodeExistsException nee) {
Expand All @@ -48,15 +48,15 @@ public static boolean attempt(ZooReaderWriter zk, String path, String reservatio
continue;
}

String idInZoo = new String(zooData, UTF_8).split(":")[0];
FateId idInZoo = FateId.from(new String(zooData, UTF_8).split(DELIMITER)[0]);

return idInZoo.equals(reservationID);
return idInZoo.equals(fateId);
}
}

}

public static void release(ZooReaderWriter zk, String path, String reservationID)
public static void release(ZooReaderWriter zk, String path, FateId fateId)
throws KeeperException, InterruptedException {
byte[] zooData;

Expand All @@ -69,11 +69,11 @@ public static void release(ZooReaderWriter zk, String path, String reservationID
}

String zooDataStr = new String(zooData, UTF_8);
String idInZoo = zooDataStr.split(":")[0];
FateId idInZoo = FateId.from(zooDataStr.split(DELIMITER)[0]);

if (!idInZoo.equals(reservationID)) {
if (!idInZoo.equals(fateId)) {
throw new IllegalStateException("Tried to release reservation " + path
+ " with data mismatch " + reservationID + " " + zooDataStr);
+ " with data mismatch " + fateId + " " + zooDataStr);
}

zk.recursiveDelete(path, NodeMissingPolicy.SKIP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.accumulo.core.metadata.schema;

import org.apache.accumulo.core.data.AbstractId;
import org.apache.accumulo.core.fate.FateTxId;
import org.apache.accumulo.core.fate.FateId;

import com.google.common.base.Preconditions;

Expand All @@ -32,15 +32,15 @@ public class TabletOperationId extends AbstractId<TabletOperationId> {
private static final long serialVersionUID = 1L;

public static String validate(String opid) {
var fields = opid.split(":");
var fields = opid.split(":", 2);
Preconditions.checkArgument(fields.length == 2, "Malformed operation id %s", opid);
try {
TabletOperationType.valueOf(fields[0]);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Malformed operation id " + opid, e);
}

if (!FateTxId.isFormatedTid(fields[1])) {
if (!FateId.isFateId(fields[1])) {
throw new IllegalArgumentException("Malformed operation id " + opid);
}

Expand All @@ -52,7 +52,7 @@ private TabletOperationId(String canonical) {
}

public TabletOperationType getType() {
var fields = canonical().split(":");
var fields = canonical().split(":", 2);
Preconditions.checkState(fields.length == 2);
return TabletOperationType.valueOf(fields[0]);
}
Expand All @@ -61,7 +61,7 @@ public static TabletOperationId from(String opid) {
return new TabletOperationId(validate(opid));
}

public static TabletOperationId from(TabletOperationType type, long txid) {
return new TabletOperationId(type + ":" + FateTxId.formatTid(txid));
public static TabletOperationId from(TabletOperationType type, FateId fateId) {
return new TabletOperationId(type + ":" + fateId);
}
}
Loading

0 comments on commit a3ec20e

Please sign in to comment.