Package org.helidb.resources.perf

Source Code of org.helidb.resources.perf.ShadowCopyTransactionalDatabaseCRSBPlusTreeConfiguration

/* HeliDB -- A simple database for Java, http://www.helidb.org
* Copyright (C) 2008, 2009 Karl Gustafsson
*
* This file is a part of HeliDB.
*
* HeliDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeliDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.helidb.resources.perf;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.entityfs.Directory;
import org.entityfs.ReadWritableFile;
import org.entityfs.fs.FSRWFileSystemBuilder;
import org.entityfs.support.log.LogAdapterHolder;
import org.entityfs.util.io.ReadWritableFileAdapter;
import org.helidb.Database;
import org.helidb.backend.DatabaseBackendFactory;
import org.helidb.backend.bpluscrs.ConstantRecordSizeBPlusTreeBackendFactory;
import org.helidb.impl.txn.sc.ShadowCopyTransactionalDatabase;
import org.helidb.impl.txn.sc.SingleFileManager;
import org.helidb.lang.serializer.IntegerNullSerializer;
import org.helidb.lang.serializer.LongSerializer;
import org.helidb.test.support.FileSupport;
import org.helidb.util.bplus.FileBackedNodeRepositoryBuilder;
import org.helidb.util.bplus.FixedSizeNodeSizeStrategy;
import org.helidb.util.bplus.KeyAndValue;
import org.helidb.util.bplus.LruCacheNodeRepositoryBuilder;
import org.helidb.util.bplus.NodeRepositoryBuilder;

public class ShadowCopyTransactionalDatabaseCRSBPlusTreeConfiguration extends AbstractTestConfiguration implements CRSTestConfiguration
{
  private Collection<ShadowCopyTransactionalDatabase<Integer, Long, KeyAndValue<Integer, Long>>> m_databases;
  private Map<Integer, File[]> m_dbFiles;
  private final int m_lruCacheSize;
  private final int m_nodeSize;

  public ShadowCopyTransactionalDatabaseCRSBPlusTreeConfiguration(int noOfDatabases, int noOfBaseRecords, int noOfAdditionalRecords, int lruCacheSize, int nodeSize)
  {
    super(noOfDatabases, noOfBaseRecords, noOfAdditionalRecords);
    m_lruCacheSize = lruCacheSize;
    m_nodeSize = nodeSize;
  }

  public String getGraphFileNamePrefix()
  {
    return "sct_crsbpt_" + m_nodeSize + "_" + m_lruCacheSize + "_";
  }

  public String getDatabaseImplementationName()
  {
    return "ShadowCopyTxnDatabase";
  }

  public String[] getBackendImplementationNames()
  {
    return new String[] { "CRSBPlusTreeBackend" };
  }

  public String getAdditionalInfo()
  {
    return "nd sz: " + m_nodeSize + (m_lruCacheSize > 0 ? " cache: " + m_lruCacheSize + "nds" : "");
  }

  public Collection<? extends Database<Integer, Long>> getDatabases()
  {
    return m_databases;
  }

  public String getHeader()
  {
    return "Shadow copy transactional database with B+ Tree backend";
  }

  public void setup(LogAdapterHolder lah)
  {
    final int noOfDatabases = getNoOfDatabases();
    m_databases = new ArrayList<ShadowCopyTransactionalDatabase<Integer, Long, KeyAndValue<Integer, Long>>>(noOfDatabases);
    m_dbFiles = new HashMap<Integer, File[]>(noOfDatabases);
    for (int i = 0; i < noOfDatabases; i++)
    {
      File f = FileSupport.createTempFile();
      ReadWritableFile ff = new ReadWritableFileAdapter(f);
      File tmpDir = FileSupport.createTempDirectory();
      Directory tmpDirD = new FSRWFileSystemBuilder().setRoot(tmpDir).create().getRootDirectory();

      NodeRepositoryBuilder<Integer> nrb = new FileBackedNodeRepositoryBuilder<Integer, Long>().setKeySerializer(IntegerNullSerializer.INSTANCE).setValueSerializer(LongSerializer.INSTANCE).setNodeSizeStrategy(new FixedSizeNodeSizeStrategy(m_nodeSize));
      if (m_lruCacheSize > 0)
      {
        nrb = new LruCacheNodeRepositoryBuilder<Integer, Long>().setProxiedBuilder(nrb).setMaxCacheSize(m_lruCacheSize);
      }
      DatabaseBackendFactory<Integer, Long, KeyAndValue<Integer, Long>> baf = new ConstantRecordSizeBPlusTreeBackendFactory<Integer, Long>(nrb, lah);
      ShadowCopyTransactionalDatabase<Integer, Long, KeyAndValue<Integer, Long>> db = new ShadowCopyTransactionalDatabase<Integer, Long, KeyAndValue<Integer, Long>>(new SingleFileManager(ff, tmpDirD), baf, false, lah);
      m_dbFiles.put(System.identityHashCode(db), new File[] { f, tmpDir });
      m_databases.add(db);
    }
  }

  public void tearDown()
  {
    for (ShadowCopyTransactionalDatabase<Integer, Long, KeyAndValue<Integer, Long>> db : m_databases)
    {
      db.close();
      deleteFile(m_dbFiles.get(System.identityHashCode(db))[0]);
      deleteFile(m_dbFiles.get(System.identityHashCode(db))[1]);
    }
    m_dbFiles = null;
    m_databases = null;
  }
}
TOP

Related Classes of org.helidb.resources.perf.ShadowCopyTransactionalDatabaseCRSBPlusTreeConfiguration

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.