Skip to content

Commit 11a3571

Browse files
fix init master key bug (#1094) (#1096)
Signed-off-by: Yaliang Wu <[email protected]> (cherry picked from commit b782f29) Co-authored-by: Yaliang Wu <[email protected]>
1 parent a966bf1 commit 11a3571

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.concurrent.CountDownLatch;
2828
import java.util.concurrent.atomic.AtomicReference;
2929

30+
import static java.util.concurrent.TimeUnit.SECONDS;
3031
import static org.opensearch.ml.common.CommonValue.MASTER_KEY;
3132
import static org.opensearch.ml.common.CommonValue.ML_CONFIG_INDEX;
3233

@@ -111,7 +112,7 @@ private void initMasterKey() {
111112
client.get(getRequest, new LatchedActionListener(ActionListener.<GetResponse>wrap(r -> {
112113
if (r.isExists()) {
113114
String masterKey = (String) r.getSourceAsMap().get(MASTER_KEY);
114-
setMasterKey(masterKey);
115+
this.masterKey = masterKey;
115116
} else {
116117
exceptionRef.set(new ResourceNotFoundException("ML encryption master key not initialized yet"));
117118
}
@@ -122,6 +123,13 @@ private void initMasterKey() {
122123
}
123124
} else {
124125
exceptionRef.set(new ResourceNotFoundException("ML encryption master key not initialized yet"));
126+
latch.countDown();
127+
}
128+
129+
try {
130+
latch.await(5, SECONDS);
131+
} catch (InterruptedException e) {
132+
throw new IllegalStateException(e);
125133
}
126134

127135
if (exceptionRef.get() != null) {
@@ -132,5 +140,8 @@ private void initMasterKey() {
132140
throw new MLException(exceptionRef.get());
133141
}
134142
}
143+
if (masterKey == null) {
144+
throw new ResourceNotFoundException("ML encryption master key not initialized yet");
145+
}
135146
}
136147
}

0 commit comments

Comments
 (0)