File tree 2 files changed +29
-2
lines changed
main/java/org/apache/helix/model
test/java/org/apache/helix/model
2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -642,8 +642,8 @@ public InstanceOperation getInstanceOperation() {
642
642
.build ();
643
643
}
644
644
645
- // Always respect the HELIX_ENABLED being set to false when instance operation is unset
646
- // for backwards compatibility.
645
+ // if instance operation is not DISABLED, we always respect the HELIX_ENABLED being set to false
646
+ // when instance operation is unset for backwards compatibility.
647
647
if (!_record .getBooleanField (InstanceConfigProperty .HELIX_ENABLED .name (),
648
648
HELIX_ENABLED_DEFAULT_VALUE )
649
649
&& (InstanceConstants .INSTANCE_DISABLED_OVERRIDABLE_OPERATIONS .contains (
@@ -656,6 +656,17 @@ public InstanceOperation getInstanceOperation() {
656
656
.build ();
657
657
}
658
658
659
+ // if instance operation is DISABLE, we override it to ENABLE if HELIX_ENABLED set to true
660
+ if (activeInstanceOperation .getOperation () == InstanceConstants .InstanceOperation .DISABLE ) {
661
+ // it is not likely that HELIX_ENABLED is unset, because when we set operation to disable,
662
+ // we always set HELIX_ENABLED to false
663
+ // If instance is enabled by old version helix (not having instance operation), the instance config
664
+ // will have HELIX_ENABLED set to true. In this case, we should override the instance operation to ENABLE
665
+ if ("true" .equals (_record .getSimpleField (InstanceConfigProperty .HELIX_ENABLED .name ()))) {
666
+ return new InstanceOperation .Builder ().setOperation (InstanceConstants .InstanceOperation .ENABLE ).build ();
667
+ }
668
+ }
669
+
659
670
return activeInstanceOperation ;
660
671
}
661
672
Original file line number Diff line number Diff line change @@ -74,6 +74,22 @@ public void testSetInstanceEnableWithReason() {
74
74
InstanceConstants .InstanceDisabledType .USER_OPERATION .toString ());
75
75
}
76
76
77
+ @ Test
78
+ public void testEnabledInstanceBackwardCompatibility () {
79
+ // if instance is disabled by instanceOperation, and enabled by HELIX_ENABLED, the instance should be enabled
80
+ InstanceConfig instanceConfig =
81
+ new InstanceConfig .Builder ().setInstanceOperation (InstanceConstants .InstanceOperation .DISABLE ).build ("id" );
82
+ Assert .assertFalse (instanceConfig .getInstanceEnabled ());
83
+ // assume an old version client enabled the instance by setting HELIX_ENABLED to true
84
+ instanceConfig .getRecord ().setSimpleField (InstanceConfig .InstanceConfigProperty .HELIX_ENABLED .name (), "true" );
85
+ Assert .assertTrue (instanceConfig .getInstanceEnabled ());
86
+ instanceConfig .setInstanceOperation (InstanceConstants .InstanceOperation .ENABLE );
87
+
88
+ // disable the instance by setting HELIX_ENABLED to false
89
+ instanceConfig .getRecord ().setSimpleField (InstanceConfig .InstanceConfigProperty .HELIX_ENABLED .name (), "false" );
90
+ Assert .assertFalse (instanceConfig .getInstanceEnabled ());
91
+ }
92
+
77
93
@ Test
78
94
public void testGetParsedDomainEmptyDomain () {
79
95
InstanceConfig instanceConfig = new InstanceConfig (new ZNRecord ("id" ));
You can’t perform that action at this time.
0 commit comments