Search in sources :

Example 6 with HeapBufferAllocator

use of org.apache.hyracks.storage.common.buffercache.HeapBufferAllocator in project asterixdb by apache.

the class LSMRTreeTestHarness method setUp.

public void setUp() throws HyracksDataException {
    ioManager = TestStorageManagerComponentHolder.getIOManager();
    ioDeviceId = 0;
    onDiskDir = ioManager.getIODevices().get(ioDeviceId).getMount() + sep + "lsm_rtree_" + simpleDateFormat.format(new Date()) + sep;
    file = ioManager.resolveAbsolutePath(onDiskDir);
    ctx = TestUtils.create(getHyracksFrameSize());
    TestStorageManagerComponentHolder.init(diskPageSize, diskNumPages, diskMaxOpenFiles);
    diskBufferCache = TestStorageManagerComponentHolder.getBufferCache(ctx.getJobletContext().getServiceContext());
    diskFileMapProvider = TestStorageManagerComponentHolder.getFileMapProvider();
    virtualBufferCaches = new ArrayList<>();
    for (int i = 0; i < numMutableComponents; i++) {
        IVirtualBufferCache virtualBufferCache = new VirtualBufferCache(new HeapBufferAllocator(), memPageSize, memNumPages / numMutableComponents);
        virtualBufferCaches.add(virtualBufferCache);
    }
    rnd.setSeed(RANDOM_SEED);
}
Also used : HeapBufferAllocator(org.apache.hyracks.storage.common.buffercache.HeapBufferAllocator) VirtualBufferCache(org.apache.hyracks.storage.am.lsm.common.impls.VirtualBufferCache) IVirtualBufferCache(org.apache.hyracks.storage.am.lsm.common.api.IVirtualBufferCache) IVirtualBufferCache(org.apache.hyracks.storage.am.lsm.common.api.IVirtualBufferCache) Date(java.util.Date)

Example 7 with HeapBufferAllocator

use of org.apache.hyracks.storage.common.buffercache.HeapBufferAllocator in project asterixdb by apache.

the class NCAppRuntimeContext method initialize.

@Override
public void initialize(boolean initialRun) throws IOException, ACIDException {
    ioManager = getServiceContext().getIoManager();
    threadExecutor = new ThreadExecutor(getServiceContext().getThreadFactory());
    fileMapManager = new FileMapManager(ioManager);
    ICacheMemoryAllocator allocator = new HeapBufferAllocator();
    IPageCleanerPolicy pcp = new DelayPageCleanerPolicy(600000);
    IPageReplacementStrategy prs = new ClockPageReplacementStrategy(allocator, storageProperties.getBufferCachePageSize(), storageProperties.getBufferCacheNumPages());
    AsynchronousScheduler.INSTANCE.init(getServiceContext().getThreadFactory());
    lsmIOScheduler = AsynchronousScheduler.INSTANCE;
    metadataMergePolicyFactory = new PrefixMergePolicyFactory();
    ILocalResourceRepositoryFactory persistentLocalResourceRepositoryFactory = new PersistentLocalResourceRepositoryFactory(ioManager, getServiceContext().getNodeId(), metadataProperties);
    localResourceRepository = (PersistentLocalResourceRepository) persistentLocalResourceRepositoryFactory.createRepository();
    IAppRuntimeContextProvider asterixAppRuntimeContextProvider = new AppRuntimeContextProviderForRecovery(this);
    txnSubsystem = new TransactionSubsystem(getServiceContext(), getServiceContext().getNodeId(), asterixAppRuntimeContextProvider, txnProperties);
    IRecoveryManager recoveryMgr = txnSubsystem.getRecoveryManager();
    SystemState systemState = recoveryMgr.getSystemState();
    if (initialRun || systemState == SystemState.PERMANENT_DATA_LOSS) {
        //delete any storage data before the resource factory is initialized
        localResourceRepository.deleteStorageData(true);
    }
    datasetLifecycleManager = new DatasetLifecycleManager(storageProperties, localResourceRepository, MetadataIndexImmutableProperties.FIRST_AVAILABLE_USER_DATASET_ID, txnSubsystem.getLogManager(), ioManager.getIODevices().size());
    isShuttingdown = false;
    activeManager = new ActiveManager(threadExecutor, getServiceContext().getNodeId(), activeProperties.getMemoryComponentGlobalBudget(), compilerProperties.getFrameSize());
    if (replicationProperties.isParticipant(getServiceContext().getNodeId())) {
        String nodeId = getServiceContext().getNodeId();
        replicaResourcesManager = new ReplicaResourcesManager(localResourceRepository, metadataProperties);
        replicationManager = new ReplicationManager(nodeId, replicationProperties, replicaResourcesManager, txnSubsystem.getLogManager(), asterixAppRuntimeContextProvider);
        //pass replication manager to replication required object
        //LogManager to replicate logs
        txnSubsystem.getLogManager().setReplicationManager(replicationManager);
        //PersistentLocalResourceRepository to replicate metadata files and delete backups on drop index
        localResourceRepository.setReplicationManager(replicationManager);
        /*
             * add the partitions that will be replicated in this node as inactive partitions
             */
        //get nodes which replicate to this node
        Set<String> remotePrimaryReplicas = replicationProperties.getRemotePrimaryReplicasIds(nodeId);
        for (String clientId : remotePrimaryReplicas) {
            //get the partitions of each client
            ClusterPartition[] clientPartitions = metadataProperties.getNodePartitions().get(clientId);
            for (ClusterPartition partition : clientPartitions) {
                localResourceRepository.addInactivePartition(partition.getPartitionId());
            }
        }
        //initialize replication channel
        replicationChannel = new ReplicationChannel(nodeId, replicationProperties, txnSubsystem.getLogManager(), replicaResourcesManager, replicationManager, getServiceContext(), asterixAppRuntimeContextProvider);
        remoteRecoveryManager = new RemoteRecoveryManager(replicationManager, this, replicationProperties);
        bufferCache = new BufferCache(ioManager, prs, pcp, fileMapManager, storageProperties.getBufferCacheMaxOpenFiles(), getServiceContext().getThreadFactory(), replicationManager);
    } else {
        bufferCache = new BufferCache(ioManager, prs, pcp, fileMapManager, storageProperties.getBufferCacheMaxOpenFiles(), getServiceContext().getThreadFactory());
    }
    /*
         * The order of registration is important. The buffer cache must registered before recovery and transaction
         * managers. Notes: registered components are stopped in reversed order
         */
    ILifeCycleComponentManager lccm = getServiceContext().getLifeCycleComponentManager();
    lccm.register((ILifeCycleComponent) bufferCache);
    /*
         * LogManager must be stopped after RecoveryManager, DatasetLifeCycleManager, and ReplicationManager
         * to process any logs that might be generated during stopping these components
         */
    lccm.register((ILifeCycleComponent) txnSubsystem.getLogManager());
    /*
         * ReplicationManager must be stopped after indexLifecycleManager and recovery manager
         * so that any logs/files generated during closing datasets or checkpoints are sent to remote replicas
         */
    if (replicationManager != null) {
        lccm.register(replicationManager);
    }
    lccm.register((ILifeCycleComponent) txnSubsystem.getRecoveryManager());
    /*
         * Stopping indexLifecycleManager will flush and close all datasets.
         */
    lccm.register((ILifeCycleComponent) datasetLifecycleManager);
    lccm.register((ILifeCycleComponent) txnSubsystem.getTransactionManager());
    lccm.register((ILifeCycleComponent) txnSubsystem.getLockManager());
    lccm.register(txnSubsystem.getCheckpointManager());
}
Also used : SystemState(org.apache.asterix.common.transactions.IRecoveryManager.SystemState) IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) DatasetLifecycleManager(org.apache.asterix.common.context.DatasetLifecycleManager) ReplicaResourcesManager(org.apache.asterix.replication.storage.ReplicaResourcesManager) IReplicaResourcesManager(org.apache.asterix.common.replication.IReplicaResourcesManager) ILocalResourceRepositoryFactory(org.apache.hyracks.storage.common.file.ILocalResourceRepositoryFactory) AppRuntimeContextProviderForRecovery(org.apache.asterix.api.common.AppRuntimeContextProviderForRecovery) ThreadExecutor(org.apache.asterix.common.api.ThreadExecutor) IAppRuntimeContextProvider(org.apache.asterix.common.transactions.IAppRuntimeContextProvider) IRemoteRecoveryManager(org.apache.asterix.common.replication.IRemoteRecoveryManager) RemoteRecoveryManager(org.apache.asterix.replication.recovery.RemoteRecoveryManager) IReplicationManager(org.apache.asterix.common.replication.IReplicationManager) ReplicationManager(org.apache.asterix.replication.management.ReplicationManager) ITransactionSubsystem(org.apache.asterix.common.transactions.ITransactionSubsystem) ILifeCycleComponentManager(org.apache.hyracks.api.lifecycle.ILifeCycleComponentManager) PersistentLocalResourceRepositoryFactory(org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepositoryFactory) IPageCleanerPolicy(org.apache.hyracks.storage.common.buffercache.IPageCleanerPolicy) IRecoveryManager(org.apache.asterix.common.transactions.IRecoveryManager) ReplicationChannel(org.apache.asterix.replication.management.ReplicationChannel) IReplicationChannel(org.apache.asterix.common.replication.IReplicationChannel) HeapBufferAllocator(org.apache.hyracks.storage.common.buffercache.HeapBufferAllocator) FileMapManager(org.apache.asterix.common.context.FileMapManager) IFileMapManager(org.apache.hyracks.storage.common.file.IFileMapManager) PrefixMergePolicyFactory(org.apache.hyracks.storage.am.lsm.common.impls.PrefixMergePolicyFactory) DelayPageCleanerPolicy(org.apache.hyracks.storage.common.buffercache.DelayPageCleanerPolicy) ICacheMemoryAllocator(org.apache.hyracks.storage.common.buffercache.ICacheMemoryAllocator) ActiveManager(org.apache.asterix.active.ActiveManager) IBufferCache(org.apache.hyracks.storage.common.buffercache.IBufferCache) BufferCache(org.apache.hyracks.storage.common.buffercache.BufferCache) IPageReplacementStrategy(org.apache.hyracks.storage.common.buffercache.IPageReplacementStrategy) ClockPageReplacementStrategy(org.apache.hyracks.storage.common.buffercache.ClockPageReplacementStrategy) ClusterPartition(org.apache.asterix.common.cluster.ClusterPartition)

Example 8 with HeapBufferAllocator

use of org.apache.hyracks.storage.common.buffercache.HeapBufferAllocator in project asterixdb by apache.

the class VirtualFreePageManagerTest method test01.

@Test
public void test01() throws HyracksDataException {
    VirtualBufferCache bufferCache = new VirtualBufferCache(new HeapBufferAllocator(), 4096, 128);
    bufferCache.open();
    FileReference fileRef = new FileReference(new IODeviceHandle(new File("target"), "workspace"), "tempfile.tmp");
    bufferCache.createFile(fileRef);
    int fileId = bufferCache.getFileMapProvider().lookupFileId(fileRef);
    bufferCache.openFile(fileId);
    VirtualFreePageManager virtualFreePageManager = new VirtualFreePageManager(bufferCache);
    virtualFreePageManager.open(fileId);
    virtualFreePageManager.init(null, null);
    testInMemoryFreePageManager(virtualFreePageManager);
    // We expect exactly the same behavior after a reset().
    virtualFreePageManager.init(null, null);
    testInMemoryFreePageManager(virtualFreePageManager);
}
Also used : IODeviceHandle(org.apache.hyracks.api.io.IODeviceHandle) HeapBufferAllocator(org.apache.hyracks.storage.common.buffercache.HeapBufferAllocator) VirtualBufferCache(org.apache.hyracks.storage.am.lsm.common.impls.VirtualBufferCache) FileReference(org.apache.hyracks.api.io.FileReference) File(java.io.File) VirtualFreePageManager(org.apache.hyracks.storage.am.lsm.common.freepage.VirtualFreePageManager) Test(org.junit.Test)

Example 9 with HeapBufferAllocator

use of org.apache.hyracks.storage.common.buffercache.HeapBufferAllocator in project asterixdb by apache.

the class LSMBTreeTestHarness method setUp.

public void setUp() throws HyracksDataException {
    ioManager = TestStorageManagerComponentHolder.getIOManager();
    ioDeviceId = 0;
    onDiskDir = ioManager.getIODevices().get(ioDeviceId).getMount() + sep + "lsm_btree_" + simpleDateFormat.format(new Date()) + sep;
    ctx = TestUtils.create(getHyracksFrameSize());
    TestStorageManagerComponentHolder.init(diskPageSize, diskNumPages, diskMaxOpenFiles);
    file = ioManager.resolveAbsolutePath(onDiskDir);
    diskBufferCache = TestStorageManagerComponentHolder.getBufferCache(ctx.getJobletContext().getServiceContext());
    diskFileMapProvider = TestStorageManagerComponentHolder.getFileMapProvider();
    virtualBufferCaches = new ArrayList<>();
    for (int i = 0; i < numMutableComponents; i++) {
        IVirtualBufferCache virtualBufferCache = new VirtualBufferCache(new HeapBufferAllocator(), memPageSize, memNumPages / numMutableComponents);
        virtualBufferCaches.add(virtualBufferCache);
    }
    rnd.setSeed(RANDOM_SEED);
}
Also used : HeapBufferAllocator(org.apache.hyracks.storage.common.buffercache.HeapBufferAllocator) VirtualBufferCache(org.apache.hyracks.storage.am.lsm.common.impls.VirtualBufferCache) IVirtualBufferCache(org.apache.hyracks.storage.am.lsm.common.api.IVirtualBufferCache) IVirtualBufferCache(org.apache.hyracks.storage.am.lsm.common.api.IVirtualBufferCache) Date(java.util.Date)

Aggregations

HeapBufferAllocator (org.apache.hyracks.storage.common.buffercache.HeapBufferAllocator)9 VirtualBufferCache (org.apache.hyracks.storage.am.lsm.common.impls.VirtualBufferCache)7 IVirtualBufferCache (org.apache.hyracks.storage.am.lsm.common.api.IVirtualBufferCache)4 Date (java.util.Date)3 ICacheMemoryAllocator (org.apache.hyracks.storage.common.buffercache.ICacheMemoryAllocator)3 VirtualFreePageManager (org.apache.hyracks.storage.am.lsm.common.freepage.VirtualFreePageManager)2 BufferCache (org.apache.hyracks.storage.common.buffercache.BufferCache)2 ClockPageReplacementStrategy (org.apache.hyracks.storage.common.buffercache.ClockPageReplacementStrategy)2 DelayPageCleanerPolicy (org.apache.hyracks.storage.common.buffercache.DelayPageCleanerPolicy)2 IBufferCache (org.apache.hyracks.storage.common.buffercache.IBufferCache)2 IPageReplacementStrategy (org.apache.hyracks.storage.common.buffercache.IPageReplacementStrategy)2 IFileMapManager (org.apache.hyracks.storage.common.file.IFileMapManager)2 Test (org.junit.Test)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ActiveManager (org.apache.asterix.active.ActiveManager)1 AppRuntimeContextProviderForRecovery (org.apache.asterix.api.common.AppRuntimeContextProviderForRecovery)1 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)1 ThreadExecutor (org.apache.asterix.common.api.ThreadExecutor)1 ClusterPartition (org.apache.asterix.common.cluster.ClusterPartition)1