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

Fix the behavior when underlying ZK throws BadVersion exception #2614

Merged
merged 1 commit into from
Sep 12, 2023
Merged
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 @@ -393,6 +393,9 @@ public AccessResult doSet(String path, T record, int expectVersion, int options)
result._retCode = RetCode.ERROR;
return result;
}
} catch (ZkBadVersionException e) {
LOG.debug("Exception while setting path: " + path, e);
throw e;
} catch (Exception e) {
LOG.error("Exception while setting path: " + path, e);
result._retCode = RetCode.ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.helix.BaseDataAccessor;
import org.apache.helix.PropertyPathBuilder;
import org.apache.helix.TestHelper;
import org.apache.helix.zookeeper.api.client.HelixZkClient;
import org.apache.helix.zookeeper.api.client.RealmAwareZkClient;
import org.apache.helix.zookeeper.datamodel.ZNRecord;
import org.apache.helix.zookeeper.datamodel.ZNRecordUpdater;
Expand All @@ -38,6 +39,7 @@
import org.apache.helix.manager.zk.ZkBaseDataAccessor.RetCode;
import org.apache.helix.zookeeper.exception.ZkClientException;
import org.apache.helix.zookeeper.zkclient.DataUpdater;
import org.apache.helix.zookeeper.zkclient.exception.ZkBadVersionException;
import org.apache.helix.zookeeper.zkclient.exception.ZkException;
import org.apache.helix.zookeeper.zkclient.exception.ZkMarshallingError;
import org.apache.helix.zookeeper.zkclient.serialize.ZkSerializer;
Expand Down Expand Up @@ -182,6 +184,35 @@ public void testSyncDoSet() {
System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}

@Test
public void testDoSetWithException() {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String testName = className + "_" + methodName;

System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));

String path = String.format("/%s/%s/%s", _rootPath, "msg_0", "submsg_0");
ZNRecord record = new ZNRecord("submsg_0");
ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
AccessResult result = accessor.doSet(path, record, -1, AccessOption.PERSISTENT);
ZNRecord getRecord = _gZkClient.readData(path);

// create mock spy for _gZkClient
HelixZkClient mockZkClient = Mockito.spy(_gZkClient);

// mock so that _gZkClient throws ZkBadVersionException
Mockito.doThrow(new ZkBadVersionException(""))
.when(mockZkClient).writeDataGetStat(Mockito.anyString(), Mockito.any(), Mockito.anyInt());

try {
accessor.doSet(path, record, getRecord.getVersion(), AccessOption.PERSISTENT);
} catch (ZkBadVersionException e) {
// OK
}
System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}

@Test
public void testSyncCreate() {
String className = TestHelper.getTestClassName();
Expand Down
Loading