bug5221: fixing the obtaining of the OutputStream for sending a replica-initiated operation to master

This commit is contained in:
Axel Uhl
2020-09-11 17:50:10 +02:00
parent f61494ef17
commit d86b38ddb5
2 changed files with 37 additions and 18 deletions
@@ -7,6 +7,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Optional;
import java.util.logging.Logger;
import com.sap.sse.common.Duration;
@@ -46,14 +47,14 @@ public interface OperationsToMasterSender<S, O extends OperationWithResult<S, ?>
final OperationWithResultWithIdWrapper<S, T> operationWithResultWithIdWrapper = new OperationWithResultWithIdWrapper<S, T>(operation);
addOperationSentToMasterForReplication(operationWithResultWithIdWrapper);
URL url = masterDescriptor.getSendReplicaInitiatedOperationToMasterURL(this.getId().toString());
// TODO shouldn't this also use the HttpUrlConnectionHelper?
HttpURLConnection connection = (HttpURLConnection) HttpUrlConnectionHelper.redirectConnectionWithBearerToken(
url, Duration.ONE_MINUTE.times(10), "POST", masterDescriptor.getBearerToken(), "application/octet-stream");
logger.info("Sending operation "+operation+" to master "+masterDescriptor+"'s replicable with ID "+this+" for initial execution and replication");
OutputStream outputStream = connection.getOutputStream();
DataOutputStream dos = new DataOutputStream(outputStream);
dos.writeUTF(getId().toString());
this.writeOperation(operationWithResultWithIdWrapper, outputStream, /* closeStream */ true);
url, Duration.ONE_MINUTE.times(10), "POST", masterDescriptor.getBearerToken(), "application/octet-stream",
Optional.of(outputStream->{
logger.info("Sending operation "+operation+" to master "+masterDescriptor+"'s replicable with ID "+this+" for initial execution and replication");
DataOutputStream dos = new DataOutputStream(outputStream);
dos.writeUTF(getId().toString());
this.writeOperation(operationWithResultWithIdWrapper, outputStream, /* closeStream */ true);
}));
final int responseCode = connection.getResponseCode();
if (responseCode < 300 || responseCode >= 500 || responseCode == 404) {
// if OK or an internal error, process as usual; in case of >= 500 this will throw an exception