Skip to content

Commit

Permalink
Introduce property shortenTransactionManagerIdIfNecessary with defaul…
Browse files Browse the repository at this point in the history
…t false
  • Loading branch information
graben committed Apr 22, 2024
1 parent d29b79d commit 49a7c20
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class NarayanaProperties {
*/
private String transactionManagerId = "1";

/**
* Shorten transactionManagerId if necessary ( > 28 bytes).
*/
private boolean shortenTransactionManagerIdIfNecessary = false;

/**
* Enable one phase commit optimization.
*/
Expand Down Expand Up @@ -146,6 +151,14 @@ public void setTransactionManagerId(String transactionManagerId) {
this.transactionManagerId = transactionManagerId;
}

public boolean isShortenTransactionManagerIdIfNecessary() {
return this.shortenTransactionManagerIdIfNecessary;
}

public void setShortenTransactionManagerIdIfNecessary(boolean shortenTransactionManagerIdIfNecessary) {
this.shortenTransactionManagerIdIfNecessary = shortenTransactionManagerIdIfNecessary;
}

public boolean isOnePhaseCommit() {
return this.onePhaseCommit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public NarayanaPropertiesInitializer(NarayanaProperties narayanaProperties) {

@Override
public void afterPropertiesSet() {
setNodeIdentifier(this.properties.getTransactionManagerId());
setNodeIdentifier(this.properties.getTransactionManagerId(), this.properties.isShortenTransactionManagerIdIfNecessary());
setXARecoveryNodes(this.properties.getXaRecoveryNodes());
setObjectStoreDir(this.properties.getLogDir());
setCommitOnePhase(this.properties.isOnePhaseCommit());
Expand All @@ -63,10 +63,12 @@ public void afterPropertiesSet() {
setExpiryScanners(this.properties.getExpiryScanners());
}

private void setNodeIdentifier(String nodeIdentifier) {
private void setNodeIdentifier(String nodeIdentifier, boolean shortenNodeNameIfNecessary) {
String verifiedNodeIdentifier = nodeIdentifier;
try {
if (nodeIdentifier != null && nodeIdentifier.getBytes(StandardCharsets.UTF_8).length > 28) {
if (nodeIdentifier != null
&& nodeIdentifier.getBytes(StandardCharsets.UTF_8).length > 28
&& shortenNodeNameIfNecessary) {
verifiedNodeIdentifier = shortenNodeIdentifier(nodeIdentifier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void shouldSetDefaultProperties() {
void shouldSetModifiedProperties() {
NarayanaProperties narayanaProperties = new NarayanaProperties();
narayanaProperties.setTransactionManagerId("test-id");
narayanaProperties.setShortenTransactionManagerIdIfNecessary(true);
narayanaProperties.setLogDir("test-dir");
narayanaProperties.setDefaultTimeout(1);
narayanaProperties.setPeriodicRecoveryPeriod(2);
Expand Down

0 comments on commit 49a7c20

Please sign in to comment.