Skip to content

Commit

Permalink
IGNITE-20733 Add GridCacheSharedContext builder (#11011)
Browse files Browse the repository at this point in the history
  • Loading branch information
timoninmaxim authored Oct 25, 2023
1 parent 2c930ab commit c861ac5
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
import org.apache.ignite.internal.processors.cache.distributed.near.GridNearAtomicCache;
import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTransactionalCache;
import org.apache.ignite.internal.processors.cache.dr.GridCacheDrManager;
import org.apache.ignite.internal.processors.cache.jta.CacheJtaManagerAdapter;
import org.apache.ignite.internal.processors.cache.mvcc.MvccCachingManager;
import org.apache.ignite.internal.processors.cache.persistence.DataRegion;
import org.apache.ignite.internal.processors.cache.persistence.DatabaseLifecycleListener;
Expand Down Expand Up @@ -3032,12 +3031,6 @@ private GridCacheSharedContext createSharedContext(
GridKernalContext kernalCtx,
Collection<CacheStoreSessionListener> storeSesLsnrs
) throws IgniteCheckedException {
IgniteTxManager tm = new IgniteTxManager();
GridCacheMvccManager mvccMgr = new GridCacheMvccManager();
GridCacheVersionManager verMgr = new GridCacheVersionManager();
GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager();
GridCachePartitionExchangeManager exchMgr = new GridCachePartitionExchangeManager();

IgniteCacheDatabaseSharedManager dbMgr;
IgnitePageStoreManager pageStoreMgr = null;
IgniteWriteAheadLogManager walMgr = null;
Expand Down Expand Up @@ -3066,45 +3059,30 @@ private GridCacheSharedContext createSharedContext(
walMgr = new FileWriteAheadLogManager(ctx);
}

WalStateManager walStateMgr = new WalStateManager(ctx);

IgniteSnapshotManager snapshotMgr = ctx.plugins().createComponent(IgniteSnapshotManager.class);

if (snapshotMgr == null)
snapshotMgr = new IgniteSnapshotManager(ctx);

GridCacheIoManager ioMgr = new GridCacheIoManager();
CacheAffinitySharedManager topMgr = new CacheAffinitySharedManager();
GridCacheSharedTtlCleanupManager ttl = new GridCacheSharedTtlCleanupManager();
PartitionsEvictManager evict = new PartitionsEvictManager();

CacheJtaManagerAdapter jta = JTA.createOptional();

MvccCachingManager mvccCachingMgr = new MvccCachingManager();

CacheDiagnosticManager diagnosticMgr = new CacheDiagnosticManager();

return new GridCacheSharedContext(
kernalCtx,
tm,
verMgr,
mvccMgr,
pageStoreMgr,
walMgr,
walStateMgr,
dbMgr,
snapshotMgr,
depMgr,
exchMgr,
topMgr,
ioMgr,
ttl,
evict,
jta,
storeSesLsnrs,
mvccCachingMgr,
diagnosticMgr
);
return GridCacheSharedContext.builder()
.setTxManager(new IgniteTxManager())
.setMvccManager(new GridCacheMvccManager())
.setVersionManager(new GridCacheVersionManager())
.setDeploymentManager(new GridCacheDeploymentManager())
.setPartitionExchangeManager(new GridCachePartitionExchangeManager())
.setDatabaseManager(dbMgr)
.setPageStoreManager(pageStoreMgr)
.setWalManager(walMgr)
.setWalStateManager(new WalStateManager(ctx))
.setSnapshotManager(snapshotMgr)
.setIoManager(new GridCacheIoManager())
.setAffinityManager(new CacheAffinitySharedManager())
.setTtlCleanupManager(new GridCacheSharedTtlCleanupManager())
.setPartitionsEvictManager(new PartitionsEvictManager())
.setJtaManager(JTA.createOptional())
.setMvccCachingManager(new MvccCachingManager())
.setDiagnosticManager(new CacheDiagnosticManager())
.build(kernalCtx, storeSesLsnrs);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ public class GridCacheSharedContext<K, V> {
/** Cluster is in read-only mode. */
private volatile boolean readOnlyMode;

/** @return GridCacheSharedContext builder instance. */
public static Builder builder() {
return new Builder();
}

/**
* @param kernalCtx Context.
* @param txMgr Transaction manager.
Expand All @@ -206,7 +211,7 @@ public class GridCacheSharedContext<K, V> {
* @param storeSesLsnrs Store session listeners.
* @param mvccCachingMgr Mvcc caching manager.
*/
public GridCacheSharedContext(
private GridCacheSharedContext(
GridKernalContext kernalCtx,
IgniteTxManager txMgr,
GridCacheVersionManager verMgr,
Expand Down Expand Up @@ -1207,4 +1212,210 @@ public void setTxManager(IgniteTxManager txMgr) {
public boolean isLazyMemoryAllocation(@Nullable DataRegion region) {
return gridConfig().isClientMode() || region == null || region.config().isLazyMemoryAllocation();
}

/** Builder for {@link GridCacheSharedContext}. */
public static class Builder {
/** */
private IgniteTxManager txMgr;

/** */
private CacheJtaManagerAdapter jtaMgr;

/** */
private GridCacheVersionManager verMgr;

/** */
private GridCacheMvccManager mvccMgr;

/** */
private IgnitePageStoreManager pageStoreMgr;

/** */
private IgniteWriteAheadLogManager walMgr;

/** */
private WalStateManager walStateMgr;

/** */
private IgniteCacheDatabaseSharedManager dbMgr;

/** */
private IgniteSnapshotManager snapshotMgr;

/** */
private GridCacheDeploymentManager<?, ?> depMgr;

/** */
private GridCachePartitionExchangeManager<?, ?> exchMgr;

/** */
private CacheAffinitySharedManager<?, ?> affMgr;

/** */
private GridCacheIoManager ioMgr;

/** */
private GridCacheSharedTtlCleanupManager ttlMgr;

/** */
private PartitionsEvictManager evictMgr;

/** */
private MvccCachingManager mvccCachingMgr;

/** */
private CacheDiagnosticManager diagnosticMgr;

/** */
private Builder() {
// No-op.
}

/** */
public <K, V> GridCacheSharedContext<K, V> build(
GridKernalContext kernalCtx,
Collection<CacheStoreSessionListener> storeSesLsnrs
) {
return new GridCacheSharedContext(
kernalCtx,
txMgr,
verMgr,
mvccMgr,
pageStoreMgr,
walMgr,
walStateMgr,
dbMgr,
snapshotMgr,
depMgr,
exchMgr,
affMgr,
ioMgr,
ttlMgr,
evictMgr,
jtaMgr,
storeSesLsnrs,
mvccCachingMgr,
diagnosticMgr
);
}

/** */
public Builder setTxManager(IgniteTxManager txMgr) {
this.txMgr = txMgr;

return this;
}

/** */
public Builder setJtaManager(CacheJtaManagerAdapter jtaMgr) {
this.jtaMgr = jtaMgr;

return this;
}

/** */
public Builder setVersionManager(GridCacheVersionManager verMgr) {
this.verMgr = verMgr;

return this;
}

/** */
public Builder setMvccManager(GridCacheMvccManager mvccMgr) {
this.mvccMgr = mvccMgr;

return this;
}

/** */
public Builder setPageStoreManager(IgnitePageStoreManager pageStoreMgr) {
this.pageStoreMgr = pageStoreMgr;

return this;
}

/** */
public Builder setWalManager(IgniteWriteAheadLogManager walMgr) {
this.walMgr = walMgr;

return this;
}

/** */
public Builder setWalStateManager(WalStateManager walStateMgr) {
this.walStateMgr = walStateMgr;

return this;
}

/** */
public Builder setDatabaseManager(IgniteCacheDatabaseSharedManager dbMgr) {
this.dbMgr = dbMgr;

return this;
}

/** */
public Builder setSnapshotManager(IgniteSnapshotManager snapshotMgr) {
this.snapshotMgr = snapshotMgr;

return this;
}

/** */
public Builder setDeploymentManager(GridCacheDeploymentManager depMgr) {
this.depMgr = depMgr;

return this;
}

/** */
public Builder setPartitionExchangeManager(GridCachePartitionExchangeManager exchMgr) {
this.exchMgr = exchMgr;

return this;
}

/** */
public Builder setAffinityManager(CacheAffinitySharedManager affMgr) {
this.affMgr = affMgr;

return this;
}

/** */
public Builder setIoManager(GridCacheIoManager ioMgr) {
this.ioMgr = ioMgr;

return this;
}

/** */
public Builder setTtlCleanupManager(GridCacheSharedTtlCleanupManager ttlMgr) {
this.ttlMgr = ttlMgr;

return this;
}

/** */
public Builder setPartitionsEvictManager(PartitionsEvictManager evictMgr) {
this.evictMgr = evictMgr;

return this;
}

/** */
public Builder setMvccCachingManager(MvccCachingManager mvccCachingMgr) {
this.mvccCachingMgr = mvccCachingMgr;

return this;
}

/** */
public Builder setDiagnosticManager(CacheDiagnosticManager diagnosticMgr) {
this.diagnosticMgr = diagnosticMgr;

return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2642,10 +2642,7 @@ public GridCloseableIterator<CacheDataRow> partitionRowIterator(GridKernalContex
CacheObjectContext coctx = new CacheObjectContext(ctx, grpName, null, false,
false, false, false, false);

GridCacheSharedContext<?, ?> sctx = new GridCacheSharedContext<>(ctx, null, null, null,
null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null);
GridCacheSharedContext<?, ?> sctx = GridCacheSharedContext.builder().build(ctx, null);

return new DataPageIterator(sctx, coctx, pageStore, partId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,9 @@ private FileDescriptor readFileDescriptor(File file, FileIOFactory ioFactory) {

dbMgr.setPageSize(iteratorParametersBuilder.pageSize);

return new GridCacheSharedContext<>(
kernalCtx, null, null, null,
null, null, null, dbMgr, null,
null, null, null, null, null,
null, null, null, null, null
);
return GridCacheSharedContext.builder()
.setDatabaseManager(dbMgr)
.build(kernalCtx, null);
}

/**
Expand Down
Loading

0 comments on commit c861ac5

Please sign in to comment.