Пример #1
0
  public AmzaActivityWALWriter(
      AmzaWALUtil amzaWALUtil, long replicateTimeoutMillis, ObjectMapper mapper) {
    this.amzaWALUtil = amzaWALUtil;
    this.replicateTimeoutMillis = replicateTimeoutMillis;

    JacksonJsonObjectTypeMarshaller<MiruPartitionedActivity> partitionedActivityMarshaller =
        new JacksonJsonObjectTypeMarshaller<>(MiruPartitionedActivity.class, mapper);
    this.activityWALKeyFunction =
        (partitionedActivity) -> {
          long activityCollisionId;
          if (partitionedActivity.type != MiruPartitionedActivity.Type.BEGIN
              && partitionedActivity.type != MiruPartitionedActivity.Type.END) {
            activityCollisionId = partitionedActivity.timestamp;
          } else {
            activityCollisionId = partitionedActivity.writerId;
          }

          try {
            return columnKeyMarshaller.toLexBytes(
                new MiruActivityWALColumnKey(
                    partitionedActivity.type.getSort(), activityCollisionId));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        };
    this.activitySerializerFunction =
        partitionedActivity -> {
          try {
            return partitionedActivityMarshaller.toBytes(partitionedActivity);
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        };
  }
Пример #2
0
 @Override
 public void delete(
     MiruTenantId tenantId, MiruPartitionId partitionId, Collection<MiruActivityWALColumnKey> keys)
     throws Exception {
   EmbeddedClient client = amzaWALUtil.getActivityClient(tenantId, partitionId);
   if (client != null) {
     try {
       client.commit(
           Consistency.leader_quorum,
           null,
           (txKeyValueStream) -> {
             for (MiruActivityWALColumnKey columnKey : keys) {
               if (!txKeyValueStream.commit(
                   columnKeyMarshaller.toLexBytes(columnKey), null, -1, true)) {
                 return false;
               }
             }
             return true;
           },
           replicateTimeoutMillis,
           TimeUnit.MILLISECONDS);
     } catch (PropertiesNotPresentException | PartitionIsDisposedException e) {
       // Ignored
     } catch (FailedToAchieveQuorumException e) {
       throw new MiruWALWrongRouteException(e);
     }
   }
 }