Skip to content

Commit 28d7fd1

Browse files
committed
Added test for fate table lock deletes
Added a test for deleting table locks from a hung fate transaction
1 parent 900976c commit 28d7fd1

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

core/src/main/java/org/apache/accumulo/core/fate/AdminUtil.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,13 @@ public boolean prepFail(TStore<T> zs, ZooReaderWriter zk, ServiceLockPath zLockM
519519
return state;
520520
}
521521

522-
public void deleteLocks(ZooReaderWriter zk, ServiceLock.ServiceLockPath path, String txidStr)
522+
/**
523+
* Removes locks at specific serviceLockPaths
524+
* <p>
525+
* When removing fate table locks, the txIdStr value must be the fate txId in hex format. See
526+
* {@link FateTxId#toHexString(String)}
527+
*/
528+
public void deleteLocks(ZooReaderWriter zk, ServiceLock.ServiceLockPath path, String txIdStr)
523529
throws KeeperException, InterruptedException {
524530
// delete any locks assoc w/ fate operation
525531
List<String> lockedIds = zk.getChildren(path.toString());
@@ -530,7 +536,7 @@ public void deleteLocks(ZooReaderWriter zk, ServiceLock.ServiceLockPath path, St
530536
String lockPath = path + "/" + id + "/" + node;
531537
byte[] data = zk.getData(path + "/" + id + "/" + node);
532538
String[] lda = new String(data, UTF_8).split(":");
533-
if (lda[1].equals(txidStr)) {
539+
if (lda[1].equals(txIdStr)) {
534540
zk.recursiveDelete(lockPath, NodeMissingPolicy.SKIP);
535541
}
536542
}

core/src/main/java/org/apache/accumulo/core/fate/FateTxId.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.accumulo.core.util.FastFormat;
2424

25+
import com.google.common.annotations.VisibleForTesting;
2526
import com.google.common.base.Preconditions;
2627

2728
public class FateTxId {
@@ -51,6 +52,18 @@ public static long fromString(String fmtTid) {
5152
return Long.parseLong(getHex(fmtTid), 16);
5253
}
5354

55+
/**
56+
* Returns the hex value of the FateTxId from a formatted fate transaction
57+
*
58+
* @param fmtTid formatted fate transaction
59+
* @return hex value of long txId
60+
*/
61+
@VisibleForTesting
62+
public static String toHexString(String fmtTid) {
63+
Preconditions.checkArgument(isFormatedTid(fmtTid));
64+
return getHex(fmtTid);
65+
}
66+
5467
/**
5568
* Formats transaction ids in a consistent way that is useful for logging and persisting.
5669
*/

test/src/main/java/org/apache/accumulo/test/fate/zookeeper/FateIT.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@
5151
import org.apache.accumulo.core.conf.Property;
5252
import org.apache.accumulo.core.data.NamespaceId;
5353
import org.apache.accumulo.core.data.TableId;
54+
import org.apache.accumulo.core.fate.AdminUtil;
5455
import org.apache.accumulo.core.fate.AgeOffStore;
5556
import org.apache.accumulo.core.fate.Fate;
5657
import org.apache.accumulo.core.fate.FateTxId;
5758
import org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus;
5859
import org.apache.accumulo.core.fate.Repo;
5960
import org.apache.accumulo.core.fate.ZooStore;
61+
import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
6062
import org.apache.accumulo.core.fate.zookeeper.ZooCache;
6163
import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
6264
import org.apache.accumulo.core.util.UtilWaitThread;
@@ -65,6 +67,7 @@
6567
import org.apache.accumulo.manager.tableOps.TraceRepo;
6668
import org.apache.accumulo.manager.tableOps.Utils;
6769
import org.apache.accumulo.server.ServerContext;
70+
import org.apache.accumulo.server.util.Admin;
6871
import org.apache.accumulo.test.util.Wait;
6972
import org.apache.accumulo.test.zookeeper.ZooKeeperTestingServer;
7073
import org.apache.zookeeper.KeeperException;
@@ -404,6 +407,51 @@ public void testCancelWhileInCall() throws Exception {
404407
assertFalse(fate.cancel(txid));
405408
}
406409

410+
/**
411+
* Test that verifies that fate table locks are created and deleted from the correct ZooKeeper
412+
* path
413+
*/
414+
@Test
415+
public void testTableLockDeleteUsesCorrectZKPath() throws Exception {
416+
417+
ConfigurationCopy config = new ConfigurationCopy();
418+
config.set(Property.GENERAL_THREADPOOL_SIZE, "2");
419+
config.set(Property.MANAGER_FATE_THREADPOOL_SIZE, "1");
420+
AdminUtil<Admin> admin = new AdminUtil<>(true);
421+
422+
callStarted = new CountDownLatch(1);
423+
finishCall = new CountDownLatch(1);
424+
425+
long txId = fate.startTransaction();
426+
String formattedTxId = FateTxId.formatTid(txId);
427+
LOG.debug("Starting test testDeleteUsesCorrectZKPath {}", formattedTxId);
428+
assertEquals(NEW, getTxStatus(zk, txId));
429+
fate.seedTransaction("TestOperation", txId, new TestOperation(NS, TID), false,
430+
"Test Delete Op");
431+
assertEquals(SUBMITTED, getTxStatus(zk, txId));
432+
fate.startTransactionRunners(config, new ScheduledThreadPoolExecutor(2));
433+
// Wait for the transaction runner to be in progress
434+
Wait.waitFor(() -> IN_PROGRESS == getTxStatus(zk, txId));
435+
436+
assertFalse(fate.cancel(txId));
437+
438+
var tableLocksPath = ServiceLock.path(ZK_ROOT + Constants.ZTABLE_LOCKS);
439+
assertFalse(zk.getChildren(tableLocksPath.toString()).isEmpty(),
440+
"Table locks at " + tableLocksPath + "do not exist");
441+
for (var tableName : zk.getChildren(tableLocksPath.toString())) {
442+
for (var tableLock : zk.getChildren(
443+
ServiceLock.path(ZK_ROOT + Constants.ZTABLE_LOCKS + "/" + tableName).toString())) {
444+
LOG.debug("Found table {} with fate lock {}", tableName, tableLock);
445+
}
446+
}
447+
448+
admin.deleteLocks(zk, tableLocksPath, FateTxId.toHexString(formattedTxId));
449+
for (var tableName : zk.getChildren(tableLocksPath.toString())) {
450+
var fateTableLocks = tableLocksPath + "/" + tableName;
451+
assertTrue(zk.getChildren(fateTableLocks).isEmpty(), " table fate locks are still present");
452+
}
453+
}
454+
407455
@Test
408456
public void testRepoFails() throws Exception {
409457
/*

0 commit comments

Comments
 (0)