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 flaky testDisableErrorLogByDefault #2869

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
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 @@ -19,6 +19,7 @@
* under the License.
*/

import com.google.common.annotations.VisibleForTesting;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.DateFormat;
Expand Down Expand Up @@ -56,8 +57,16 @@
public class StatusUpdateUtil {
static Logger _logger = LoggerFactory.getLogger(StatusUpdateUtil.class);

public static final boolean ERROR_LOG_TO_ZK_ENABLED =
private static boolean ERROR_LOG_TO_ZK_ENABLED =
Boolean.getBoolean(SystemPropertyKeys.STATEUPDATEUTIL_ERROR_PERSISTENCY_ENABLED);
public static boolean isErrorLogToZkEnabled() {
return ERROR_LOG_TO_ZK_ENABLED;
}

@VisibleForTesting
public static void setErrorLogToZkEnabled(boolean enabled) {
ERROR_LOG_TO_ZK_ENABLED = enabled;
}

public static class Transition implements Comparable<Transition> {
private final String _msgID;
Expand Down Expand Up @@ -555,9 +564,10 @@ void publishStatusUpdateRecord(ZNRecord record, Message message, Level level,
*/
void publishErrorRecord(ZNRecord record, String instanceName, String updateSubPath,
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using this approach to define param, let's do this:

create a new function:

void publishErrorRecord(ZNRecord record, String instanceName, String updateSubPath,String updateKey, String sessionId, HelixDataAccessor accessor, boolean isController, boolean logToZK);

Put all existing logic in this one and leverage this boolean flag to check.

For the old API, you can call this by passing
ERROR_LOG_TO_ZK_ENABLED

String updateKey, String sessionId, HelixDataAccessor accessor, boolean isController) {
if (!ERROR_LOG_TO_ZK_ENABLED) {
if (!isErrorLogToZkEnabled()) {
return;
}

Builder keyBuilder = accessor.keyBuilder();
if (isController) {
// TODO need to fix: ERRORS_CONTROLLER doesn't have a form of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.helix.model.ClusterConfig;
import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.ParticipantHistory;
import org.apache.helix.util.StatusUpdateUtil;
import org.apache.helix.zookeeper.datamodel.ZNRecord;
import org.apache.helix.ZkTestHelper;
import org.apache.helix.common.ZkTestBase;
Expand All @@ -65,7 +66,6 @@
import org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

Expand All @@ -74,20 +74,11 @@ public class TestParticipantManager extends ZkTestBase {
private final String _clusterName = TestHelper.getTestClassName();
private final ExecutorService _executor = Executors.newFixedThreadPool(1);

static {
System.setProperty(SystemPropertyKeys.STATEUPDATEUTIL_ERROR_PERSISTENCY_ENABLED, "true");
}

@AfterMethod
public void afterMethod(Method testMethod, ITestContext testContext) {
deleteCluster(_clusterName);
}

@AfterClass
public void afterClass() {
System.clearProperty(SystemPropertyKeys.STATEUPDATEUTIL_ERROR_PERSISTENCY_ENABLED);
}

@Test
public void simpleIntegrationTest() throws Exception {
TestHelper.setupCluster(_clusterName, ZK_ADDR, 12918, // participant port
Expand Down Expand Up @@ -439,6 +430,7 @@ public void testSessionExpiryInTransition() throws Exception {
String newSessionId = participants[0].getSessionId();
Assert.assertNotSame(newSessionId, oldSessionId);

StatusUpdateUtil.setErrorLogToZkEnabled(true);
// assert interrupt exception error in old session
String errPath = PropertyPathBuilder.instanceError(_clusterName, "localhost_12918", oldSessionId,
"TestDB0", "TestDB0_0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@

import org.apache.helix.HelixConstants;
import org.apache.helix.PropertyPathBuilder;
import org.apache.helix.SystemPropertyKeys;
import org.apache.helix.TestHelper;
import org.apache.helix.common.ZkTestBase;
import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.messaging.handling.HelixStateTransitionHandler;
import org.apache.helix.model.Message;
import org.apache.helix.model.StatusUpdate;
import org.apache.helix.zookeeper.datamodel.ZNRecord;
import org.apache.helix.zookeeper.zkclient.exception.ZkException;
import org.testng.Assert;
Expand All @@ -45,17 +43,6 @@ public class TestStatusUpdateUtil extends ZkTestBase {
private Message message = new Message(Message.MessageType.STATE_TRANSITION, "Some unique id");
private MockParticipantManager[] participants = new MockParticipantManager[n];


static void setFinalStatic(Field field, Object newValue) throws Exception {
field.setAccessible(true);

Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

field.set(null, newValue);
}

@AfterClass
public void afterClass() {
for (int i = 0; i < n; i++) {
Expand Down Expand Up @@ -98,7 +85,7 @@ public void beforeClass() throws Exception {
@Test(dependsOnMethods = "testDisableErrorLogByDefault")
public void testEnableErrorLog() throws Exception {
StatusUpdateUtil statusUpdateUtil = new StatusUpdateUtil();
setFinalStatic(StatusUpdateUtil.class.getField("ERROR_LOG_TO_ZK_ENABLED"), true);
StatusUpdateUtil.setErrorLogToZkEnabled(true);

Exception e = new RuntimeException("test exception");
statusUpdateUtil.logError(message, HelixStateTransitionHandler.class, e,
Expand All @@ -118,16 +105,16 @@ public void testEnableErrorLog() throws Exception {
@Test
public void testDisableErrorLogByDefault() throws Exception {
StatusUpdateUtil statusUpdateUtil = new StatusUpdateUtil();
setFinalStatic(StatusUpdateUtil.class.getField("ERROR_LOG_TO_ZK_ENABLED"), false);
StatusUpdateUtil.setErrorLogToZkEnabled(false);

Exception e = new RuntimeException("test exception");
statusUpdateUtil.logError(message, HelixStateTransitionHandler.class, e,
"test status update", participants[0]);

// assert by default, not logged to Zookeeper
String errPath = PropertyPathBuilder
.instanceError(clusterName, "localhost_12918", participants[0].getSessionId(), "TestDB",
"TestDB_0");

try {
ZNRecord error = _gZkClient.readData(errPath);
Assert.fail("not expecting being able to send error logs to ZK by default.");
Expand Down