Thank you Manuel for the prompt response. Here is what I am planning on doing.
I have the following snippet as shown below and I am using StatefulSet PVC with ReadWriteOnce access mode.
My understand is that with a StatefulSet, the pod names will have an ordinal starting at index 0.
For example: pod-abcde-0, pod-abcde-1, pod-abcde-2 and with my setup the log directory for the pods will be:
/base/log/dir/pod-abcde-0/base/log/dir/pod-abcde-0
/base/log/dir/pod-abcde-1/base/log/dir/pod-abcde-0
/base/log/dir/pod-abcde-2/ObjectStore.....
And so if say pod-abcde-1 crashes for some reason, the controller will restart it with same name and ordinal since
it's a StatefulSet which will be pod-abcde-1 and therefore will be able to read and recover from same log directory.
I am hoping this will work.
@Configuration
public class NarayanaCorePropertiesConfig {
@PostConstruct
public void setNodeIdentifier() throws CoreEnvironmentBeanException {
com.arjuna
.ats
.arjuna
.common
.arjPropertyManager
.getCoreEnvironmentBean()
.setNodeIdentifier(NarayanaUtil.getNodeIdentifier());
}
}
@PostConstruct
public void setTransactionLogDir() {
String podLogDir = baseTransLogDir + "/" + NarayanaUtil.getNodeIdentifier();
System.setProperty("user.dir", podLogDir);
System.setProperty("ObjectStoreEnvironmentBean.objectStoreDir", podLogDir);
}
public class NarayanaUtil {
private NarayanaUtil() {}
private static final String DEFAULT_HOST = "localhost-v1";
public static String getNodeIdentifier() {
String podName = System.getenv().getOrDefault("HOSTNAME", DEFAULT_HOST);
if (DEFAULT_HOST.equals(podName)) {
return podName;
}
// Remove last 17 characters from the pod name
String newPodName = podName.substring(0, podName.length() - 17);
// Check if the new pod name's length is greater than 28
if (newPodName.length() > 28) {
// If greater, return the first 28 characters
return newPodName.substring(0, 28);
}
return newPodName;
}
}