use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class DistributedDatabaseOperateImpl method update.
@Override
public Boolean update(List<ModifyRequest> sqlContext, BiConsumer<Boolean, Throwable> consumer) {
try {
// Since the SQL parameter is Object[], in order to ensure that the types of
// array elements are not lost, the serialization here is done using the java-specific
// serialization framework, rather than continuing with the protobuff
LoggerUtils.printIfDebugEnabled(LogUtil.DEFAULT_LOG, "modifyRequests info : {}", sqlContext);
// {timestamp}-{group}-{ip:port}-{signature}
final String key = System.currentTimeMillis() + "-" + group() + "-" + memberManager.getSelf().getAddress() + "-" + MD5Utils.md5Hex(sqlContext.toString(), Constants.ENCODE);
WriteRequest request = WriteRequest.newBuilder().setGroup(group()).setKey(key).setData(ByteString.copyFrom(serializer.serialize(sqlContext))).putAllExtendInfo(EmbeddedStorageContextUtils.getCurrentExtendInfo()).setType(sqlContext.getClass().getCanonicalName()).build();
if (Objects.isNull(consumer)) {
Response response = this.protocol.write(request);
if (response.getSuccess()) {
return true;
}
LogUtil.DEFAULT_LOG.error("execute sql modify operation failed : {}", response.getErrMsg());
return false;
} else {
this.protocol.writeAsync(request).whenComplete((BiConsumer<Response, Throwable>) (response, ex) -> {
String errMsg = Objects.isNull(ex) ? response.getErrMsg() : ExceptionUtil.getCause(ex).getMessage();
consumer.accept(response.getSuccess(), StringUtils.isBlank(errMsg) ? null : new NJdbcException(errMsg));
});
}
return true;
} catch (TimeoutException e) {
LogUtil.FATAL_LOG.error("An timeout exception occurred during the update operation");
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
} catch (Throwable e) {
LogUtil.FATAL_LOG.error("An exception occurred during the update operation : {}", e);
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e.toString());
}
}
use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class PersistentClientOperationServiceImpl method deregisterInstance.
@Override
public void deregisterInstance(Service service, Instance instance, String clientId) {
final InstanceStoreRequest request = new InstanceStoreRequest();
request.setService(service);
request.setInstance(instance);
request.setClientId(clientId);
final WriteRequest writeRequest = WriteRequest.newBuilder().setGroup(group()).setData(ByteString.copyFrom(serializer.serialize(request))).setOperation(DataOperation.DELETE.name()).build();
try {
protocol.write(writeRequest);
} catch (Exception e) {
throw new NacosRuntimeException(NacosException.SERVER_ERROR, e);
}
}
use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class NamingMetadataOperateService method updateServiceMetadata.
/**
* Update service metadata.
*
* @param service service of metadata
* @param serviceMetadata metadata
*/
public void updateServiceMetadata(Service service, ServiceMetadata serviceMetadata) {
MetadataOperation<ServiceMetadata> operation = buildMetadataOperation(service);
operation.setMetadata(serviceMetadata);
WriteRequest operationLog = WriteRequest.newBuilder().setGroup(Constants.SERVICE_METADATA).setOperation(DataOperation.CHANGE.name()).setData(ByteString.copyFrom(serializer.serialize(operation))).build();
submitMetadataOperation(operationLog);
}
use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class NamingMetadataOperateService method deleteInstanceMetadata.
/**
* Delete instance metadata.
*
* @param service service of metadata
* @param metadataId instance metadata Id
*/
public void deleteInstanceMetadata(Service service, String metadataId) {
MetadataOperation<InstanceMetadata> operation = buildMetadataOperation(service);
operation.setTag(metadataId);
WriteRequest operationLog = WriteRequest.newBuilder().setGroup(Constants.INSTANCE_METADATA).setOperation(DataOperation.DELETE.name()).setData(ByteString.copyFrom(serializer.serialize(operation))).build();
submitMetadataOperation(operationLog);
}
use of com.alibaba.nacos.consistency.entity.WriteRequest in project nacos by alibaba.
the class NamingMetadataOperateService method updateInstanceMetadata.
/**
* Update instance metadata.
*
* @param service service of metadata
* @param metadataId instance metadataId Id
* @param instanceMetadata metadata
*/
public void updateInstanceMetadata(Service service, String metadataId, InstanceMetadata instanceMetadata) {
MetadataOperation<InstanceMetadata> operation = buildMetadataOperation(service);
operation.setTag(metadataId);
operation.setMetadata(instanceMetadata);
WriteRequest operationLog = WriteRequest.newBuilder().setGroup(Constants.INSTANCE_METADATA).setOperation(DataOperation.CHANGE.name()).setData(ByteString.copyFrom(serializer.serialize(operation))).build();
submitMetadataOperation(operationLog);
}
Aggregations