protected Shard(AbstractBuilder<?, ?> builder) { super( builder.getId().toString(), builder.getPeerAddresses(), Optional.of(builder.getDatastoreContext().getShardRaftConfig()), DataStoreVersions.CURRENT_VERSION); this.name = builder.getId().toString(); this.datastoreContext = builder.getDatastoreContext(); this.restoreFromSnapshot = builder.getRestoreFromSnapshot(); setPersistence(datastoreContext.isPersistent()); LOG.info("Shard created : {}, persistent : {}", name, datastoreContext.isPersistent()); store = new ShardDataTree(builder.getSchemaContext(), builder.getTreeType()); shardMBean = ShardMBeanFactory.getShardStatsMBean( name.toString(), datastoreContext.getDataStoreMXBeanType()); shardMBean.setShard(this); if (isMetricsCaptureEnabled()) { getContext().become(new MeteringBehavior(this)); } commitCoordinator = new ShardCommitCoordinator( store, datastoreContext.getShardCommitQueueExpiryTimeoutInMillis(), datastoreContext.getShardTransactionCommitQueueCapacity(), LOG, this.name); setTransactionCommitTimeout(); // create a notifier actor for each cluster member roleChangeNotifier = createRoleChangeNotifier(name.toString()); appendEntriesReplyTracker = new MessageTracker( AppendEntriesReply.class, getRaftActorContext().getConfigParams().getIsolatedCheckIntervalInMillis()); transactionActorFactory = new ShardTransactionActorFactory( store, datastoreContext, new Dispatchers(context().system().dispatchers()) .getDispatcherPath(Dispatchers.DispatcherType.Transaction), self(), getContext(), shardMBean); snapshotCohort = new ShardSnapshotCohort(transactionActorFactory, store, LOG, this.name); messageRetrySupport = new ShardTransactionMessageRetrySupport(this); }
public TreeType getTreeType() { switch (datastoreContext.getLogicalStoreType()) { case CONFIGURATION: return TreeType.CONFIGURATION; case OPERATIONAL: return TreeType.OPERATIONAL; } throw new IllegalStateException( "Unhandled logical store type " + datastoreContext.getLogicalStoreType()); }
protected void onDatastoreContext(DatastoreContext context) { datastoreContext = context; commitCoordinator.setQueueCapacity(datastoreContext.getShardTransactionCommitQueueCapacity()); setTransactionCommitTimeout(); if (datastoreContext.isPersistent() && !persistence().isRecoveryApplicable()) { setPersistence(true); } else if (!datastoreContext.isPersistent() && persistence().isRecoveryApplicable()) { setPersistence(false); } updateConfigParams(datastoreContext.getShardRaftConfig()); }
@Override public ShardTransaction create() throws Exception { final ShardTransaction tx; switch (type) { case READ_ONLY: tx = new ShardReadTransaction( transaction, shardActor, shardStats, transactionID, txnClientVersion); break; case READ_WRITE: tx = new ShardReadWriteTransaction( (ReadWriteShardDataTreeTransaction) transaction, shardActor, shardStats, transactionID, txnClientVersion); break; case WRITE_ONLY: tx = new ShardWriteTransaction( (ReadWriteShardDataTreeTransaction) transaction, shardActor, shardStats, transactionID, txnClientVersion); break; default: throw new IllegalArgumentException("Unhandled transaction type " + type); } tx.getContext().setReceiveTimeout(datastoreContext.getShardTransactionIdleTimeout()); return tx; }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); schemaContext = TestModel.createTestContext(); doReturn(schemaContext).when(actorContext).getSchemaContext(); doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext(); }
private void setTransactionCommitTimeout() { transactionCommitTimeout = TimeUnit.MILLISECONDS.convert( datastoreContext.getShardTransactionCommitTimeoutInSeconds(), TimeUnit.SECONDS) / 2; }