<commit_before>package nl.vu.cs.dynamite.storage.berkeleydb;

import java.io.File;

import nl.vu.cs.ajira.Context;
import nl.vu.cs.ajira.actions.ActionContext;
import nl.vu.cs.ajira.chains.Location;
import nl.vu.cs.ajira.data.types.TInt;
import nl.vu.cs.ajira.data.types.TLong;
import nl.vu.cs.ajira.data.types.Tuple;
import nl.vu.cs.ajira.datalayer.InputLayer;
import nl.vu.cs.ajira.datalayer.TupleIterator;
import nl.vu.cs.ajira.utils.Configuration;
import nl.vu.cs.ajira.utils.Utils;
import nl.vu.cs.dynamite.storage.BTreeInterface;
import nl.vu.cs.dynamite.storage.DBType;
import nl.vu.cs.dynamite.storage.WritingSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.OperationStatus;
import com.sleepycat.je.StatsConfig;

public class BerkeleydbLayer extends InputLayer implements BTreeInterface {

	static final Logger log = LoggerFactory.getLogger(BerkeleydbLayer.class);

	final public static String DB_INPUT = "berkeleydb.inputpath";
	final public static String COMPRESS_KEYS = "berkeleydb.compress";

	private static Environment env = null;
	private static Database spo = null;
	private static Database sop = null;
	private static Database pos = null;
	private static Database pso = null;
	private static Database ops = null;
	private static Database osp = null;
	private static Database t2n = null;
	private static Database n2t = null;

	private DatabaseConfig dbConfig;
	private boolean isInitialized = false;
	private boolean compressedKeys;
	
	private static int counter = 0;

	public static void setInputDir(Configuration conf, String inputDir) {
		conf.set(DB_INPUT, inputDir);
	}

	private void configureEnvironment(EnvironmentConfig envConfig) {
		envConfig.setAllowCreate(true);
		envConfig.setAllowCreateVoid(true);
		envConfig.setConfigParam(EnvironmentConfig.LOG_FILE_MAX, "200000000");
		envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CLEANER, "false");
		envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CHECKPOINTER,
				"false");
		envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_IN_COMPRESSOR,
				"false");
	}

	private void configureDatabases(DatabaseConfig dbConfig) {
		dbConfig.setDeferredWrite(true);
		dbConfig.setKeyPrefixing(true);
		dbConfig.setTransactional(false);
		dbConfig.setAllowCreate(true);
		dbConfig.setAllowCreateVoid(true);
	}

	private Database loadDb(DBType db) throws Exception {
		synchronized (BerkeleydbLayer.class) {
			Database database = fromDbToObj(db);
			if (database == null) {
				database = env.openDatabase(null, fromDbToName(db), dbConfig);
				initDatabase(db, database);
			}
			return database;
		}
	}<commit_msg>Made evictor be more inclined to keep internal nodes of btree in memory<commit_after>package nl.vu.cs.dynamite.storage.berkeleydb;

import java.io.File;

import nl.vu.cs.ajira.Context;
import nl.vu.cs.ajira.actions.ActionContext;
import nl.vu.cs.ajira.chains.Location;
import nl.vu.cs.ajira.data.types.TInt;
import nl.vu.cs.ajira.data.types.TLong;
import nl.vu.cs.ajira.data.types.Tuple;
import nl.vu.cs.ajira.datalayer.InputLayer;
import nl.vu.cs.ajira.datalayer.TupleIterator;
import nl.vu.cs.ajira.utils.Configuration;
import nl.vu.cs.ajira.utils.Utils;
import nl.vu.cs.dynamite.storage.BTreeInterface;
import nl.vu.cs.dynamite.storage.DBType;
import nl.vu.cs.dynamite.storage.WritingSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.OperationStatus;
import com.sleepycat.je.StatsConfig;

public class BerkeleydbLayer extends InputLayer implements BTreeInterface {

	static final Logger log = LoggerFactory.getLogger(BerkeleydbLayer.class);

	final public static String DB_INPUT = "berkeleydb.inputpath";
	final public static String COMPRESS_KEYS = "berkeleydb.compress";

	private static Environment env = null;
	private static Database spo = null;
	private static Database sop = null;
	private static Database pos = null;
	private static Database pso = null;
	private static Database ops = null;
	private static Database osp = null;
	private static Database t2n = null;
	private static Database n2t = null;

	private DatabaseConfig dbConfig;
	private boolean isInitialized = false;
	private boolean compressedKeys;
	
	private static int counter = 0;

	public static void setInputDir(Configuration conf, String inputDir) {
		conf.set(DB_INPUT, inputDir);
	}

	private void configureEnvironment(EnvironmentConfig envConfig) {
		envConfig.setAllowCreate(true);
		envConfig.setAllowCreateVoid(true);
		envConfig.setConfigParam(EnvironmentConfig.LOG_FILE_MAX, "200000000");
		// envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CLEANER, "false");
                envConfig.setConfigParam(EnvironmentConfig.EVICTOR_LRU_ONLY, "false");
		envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CHECKPOINTER,
				"false");
		envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_IN_COMPRESSOR,
				"false");
	}

	private void configureDatabases(DatabaseConfig dbConfig) {
		dbConfig.setDeferredWrite(true);
		dbConfig.setKeyPrefixing(true);
		dbConfig.setTransactional(false);
		dbConfig.setAllowCreate(true);
		dbConfig.setAllowCreateVoid(true);
	}

	private Database loadDb(DBType db) throws Exception {
		synchronized (BerkeleydbLayer.class) {
			Database database = fromDbToObj(db);
			if (database == null) {
				database = env.openDatabase(null, fromDbToName(db), dbConfig);
				initDatabase(db, database);
			}
			return database;
		}
	}
{'fraction_non_alphanumeric': 0.09772099447513811, 'fraction_numerical': 0.004834254143646409, 'mean_word_length': 5.451002227171492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '827112', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1858, 'n_words': 386}