use of nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.IsCleanHandler in project timbuctoo by HuygensING.
the class BdbPersistentEnvironmentCreator method getDatabase.
@Override
public <KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName, boolean allowDuplicates, EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, IsCleanHandler<KeyT, ValueT> cleanHandler) throws BdbDbCreationException {
DatabaseConfig config = new DatabaseConfig();
config.setAllowCreate(true);
config.setDeferredWrite(true);
config.setSortedDuplicates(allowDuplicates);
String environmentKey = environmentKey(userId, dataSetId);
String databaseKey = environmentKey + "_" + databaseName;
if (!databases.containsKey(databaseKey)) {
if (!environmentMap.containsKey(environmentKey)) {
try {
File dbDir = fileHelper.pathInDataSet(userId, dataSetId, "databases");
Environment dataSetEnvironment = new Environment(dbDir, configuration);
environmentMap.put(environmentKey, dataSetEnvironment);
} catch (DatabaseException e) {
throw new BdbDbCreationException(e);
}
}
try {
databases.put(databaseKey, environmentMap.get(environmentKey).openDatabase(null, databaseName, config));
} catch (DatabaseException e) {
throw new BdbDbCreationException(e);
}
}
return new BdbWrapper<>(environmentMap.get(environmentKey), databases.get(databaseKey), config, keyBinder, valueBinder, cleanHandler);
}
use of nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.IsCleanHandler in project timbuctoo by HuygensING.
the class DataSet method dataSet.
public static DataSet dataSet(DataSetMetaData metadata, ExecutorService executorService, String rdfPrefix, BdbEnvironmentCreator dataStoreFactory, Runnable onUpdated, DataSetStorage dataSetStorage) throws IOException, DataStoreCreationException {
String userId = metadata.getOwnerId();
String dataSetId = metadata.getDataSetId();
File descriptionFile = dataSetStorage.getResourceSyncDescriptionFile();
FileStorage fileStorage = dataSetStorage.getFileStorage();
ImportManager importManager = new ImportManager(dataSetStorage.getLogList(), fileStorage, fileStorage, dataSetStorage.getLogStorage(), executorService, dataSetStorage.getRdfIo(), onUpdated);
try {
importManager.subscribeToRdf(new RdfDescriptionSaver(descriptionFile, metadata.getBaseUri(), importManager.getImportStatus()));
} catch (ParserConfigurationException | SAXException e) {
LOG.error("Could not construct import manager of data set", e);
}
final TupleBinding<String> stringBinding = TupleBinding.getPrimitiveBinding(String.class);
try {
StringStringIsCleanHandler stringStringIsCleanHandler = new StringStringIsCleanHandler();
BdbTripleStore quadStore = new BdbTripleStore(dataStoreFactory.getDatabase(userId, dataSetId, "rdfData", true, stringBinding, stringBinding, stringStringIsCleanHandler));
final BdbTypeNameStore typeNameStore = new BdbTypeNameStore(new BdbBackedData(dataStoreFactory.getDatabase(userId, dataSetId, "typenames", false, stringBinding, stringBinding, stringStringIsCleanHandler)), rdfPrefix);
final BdbSchemaStore schema = new BdbSchemaStore(new BdbBackedData(dataStoreFactory.getDatabase(userId, dataSetId, "schema", false, stringBinding, stringBinding, stringStringIsCleanHandler)), importManager.getImportStatus());
final BdbTruePatchStore truePatchStore = new BdbTruePatchStore(dataStoreFactory.getDatabase(userId, dataSetId, "truePatch", true, stringBinding, stringBinding, stringStringIsCleanHandler));
final TupleBinding<Integer> integerBinding = TupleBinding.getPrimitiveBinding(Integer.class);
final UpdatedPerPatchStore updatedPerPatchStore = new UpdatedPerPatchStore(dataStoreFactory.getDatabase(userId, dataSetId, "updatedPerPatch", true, integerBinding, stringBinding, new IsCleanHandler<Integer, String>() {
@Override
public Integer getKey() {
return Integer.MAX_VALUE;
}
@Override
public String getValue() {
return "isClean";
}
}));
final BdbRmlDataSourceStore rmlDataSourceStore = new BdbRmlDataSourceStore(dataStoreFactory.getDatabase(userId, dataSetId, "rmlSource", true, stringBinding, stringBinding, stringStringIsCleanHandler), importManager.getImportStatus());
VersionStore versionStore = new VersionStore(dataStoreFactory.getDatabase(userId, dataSetId, "versions", false, stringBinding, integerBinding, new IsCleanHandler<String, Integer>() {
@Override
public String getKey() {
return "isClean";
}
@Override
public Integer getValue() {
return Integer.MAX_VALUE;
}
}));
final StoreUpdater storeUpdater = new StoreUpdater(dataStoreFactory, quadStore, typeNameStore, truePatchStore, updatedPerPatchStore, Lists.newArrayList(schema, rmlDataSourceStore), versionStore, importManager.getImportStatus());
importManager.subscribeToRdf(storeUpdater);
ImmutableDataSet dataSet = ImmutableDataSet.builder().ownerId(userId).dataSetName(dataSetId).bdbEnvironmentCreator(dataStoreFactory).metadata(metadata).quadStore(quadStore).typeNameStore(typeNameStore).schemaStore(schema).dataSource(new RdfDataSourceFactory(rmlDataSourceStore)).schemaStore(schema).importManager(importManager).dataSetStorage(dataSetStorage).build();
importManager.init(dataSet);
if (!quadStore.isClean() || !typeNameStore.isClean() || !schema.isClean() || !truePatchStore.isClean() || !updatedPerPatchStore.isClean() || !rmlDataSourceStore.isClean() || !versionStore.isClean()) {
LOG.error("Data set '{}__{}' data is corrupted, starting to reimport.", userId, dataSetId);
quadStore.empty();
typeNameStore.empty();
schema.empty();
truePatchStore.empty();
updatedPerPatchStore.empty();
rmlDataSourceStore.empty();
versionStore.empty();
importManager.reprocessLogs();
} else {
// process unprocessed logs
importManager.processLogs();
}
return dataSet;
} catch (BdbDbCreationException e) {
throw new DataStoreCreationException(e.getCause());
}
}
use of nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.IsCleanHandler in project timbuctoo by HuygensING.
the class BdbNonPersistentEnvironmentCreator method getDatabase.
@Override
public <KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName, boolean allowDuplicates, EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, IsCleanHandler<KeyT, ValueT> isCleanHandler) throws BdbDbCreationException {
try {
DatabaseConfig config = new DatabaseConfig();
config.setAllowCreate(true);
config.setDeferredWrite(true);
config.setSortedDuplicates(allowDuplicates);
String environmentKey = environmentKey(userId, dataSetId);
File envHome = new File(dbHome, environmentKey);
envHome.mkdirs();
Environment dataSetEnvironment = new Environment(envHome, configuration);
Database database = dataSetEnvironment.openDatabase(null, databaseName, config);
databases.put(environmentKey + "_" + databaseName, database);
environmentMap.put(environmentKey, dataSetEnvironment);
return new BdbWrapper<>(dataSetEnvironment, database, config, keyBinder, valueBinder, isCleanHandler);
} catch (DatabaseException e) {
throw new BdbDbCreationException(e);
}
}
Aggregations