Search in sources :

Example 1 with WorkerStorage

use of com.bakdata.conquery.io.storage.WorkerStorage in project conquery by bakdata.

the class Worker method newWorker.

public static Worker newWorker(@NonNull Dataset dataset, @NonNull ThreadPoolDefinition queryThreadPoolDefinition, @NonNull ExecutorService jobsExecutorService, @NonNull StoreFactory config, @NonNull String directory, @NonNull Validator validator, boolean failOnError, int entityBucketSize) {
    WorkerStorage workerStorage = new WorkerStorage(validator, "worker_" + directory);
    // On the worker side we don't have to set the object writer vor ForwardToWorkerMessages in WorkerInformation
    WorkerInformation info = new WorkerInformation();
    info.setDataset(dataset.getId());
    info.setName(directory);
    info.setEntityBucketSize(entityBucketSize);
    workerStorage.openStores(config);
    workerStorage.loadData();
    workerStorage.updateDataset(dataset);
    workerStorage.setWorker(info);
    return new Worker(queryThreadPoolDefinition, workerStorage, jobsExecutorService, failOnError, entityBucketSize);
}
Also used : WorkerStorage(com.bakdata.conquery.io.storage.WorkerStorage) ModificationShieldedWorkerStorage(com.bakdata.conquery.io.storage.ModificationShieldedWorkerStorage)

Example 2 with WorkerStorage

use of com.bakdata.conquery.io.storage.WorkerStorage in project conquery by bakdata.

the class ShardNode method run.

@Override
protected void run(Environment environment, Namespace namespace, ConqueryConfig config) throws Exception {
    this.environment = environment;
    connector = new NioSocketConnector();
    jobManager = new JobManager(getName(), config.isFailOnError());
    synchronized (environment) {
        environment.lifecycle().manage(this);
        validator = environment.getValidator();
        scheduler = environment.lifecycle().scheduledExecutorService("Scheduled Messages").build();
    }
    this.config = config;
    config.initialize(this);
    scheduler.scheduleAtFixedRate(this::reportJobManagerStatus, 30, 1, TimeUnit.SECONDS);
    final ObjectMapper binaryMapper = config.configureObjectMapper(Jackson.copyMapperAndInjectables(Jackson.BINARY_MAPPER));
    ((MutableInjectableValues) binaryMapper.getInjectableValues()).add(Validator.class, environment.getValidator());
    workers = new Workers(getConfig().getQueries().getExecutionPool(), binaryMapper, getConfig().getCluster().getEntityBucketSize());
    final Collection<WorkerStorage> workerStorages = config.getStorage().loadWorkerStorages();
    for (WorkerStorage workerStorage : workerStorages) {
        workers.createWorker(workerStorage, config.isFailOnError());
    }
    log.info("All Worker Storages loaded: {}", workers.getWorkers().size());
}
Also used : NioSocketConnector(org.apache.mina.transport.socket.nio.NioSocketConnector) Workers(com.bakdata.conquery.models.worker.Workers) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) JobManager(com.bakdata.conquery.models.jobs.JobManager) WorkerStorage(com.bakdata.conquery.io.storage.WorkerStorage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with WorkerStorage

use of com.bakdata.conquery.io.storage.WorkerStorage in project conquery by bakdata.

the class XodusStoreFactory method loadNamespacedStores.

private <T extends NamespacedStorage> Queue<T> loadNamespacedStores(String prefix, Function<String, T> creator, Set<String> storesToTest) throws InterruptedException {
    File baseDir = getDirectory().toFile();
    if (baseDir.mkdirs()) {
        log.warn("Had to create Storage Dir at `{}`", baseDir);
    }
    Queue<T> storages = new ConcurrentLinkedQueue<>();
    ExecutorService loaders = Executors.newFixedThreadPool(getNThreads());
    for (File directory : Objects.requireNonNull(baseDir.listFiles((file, name) -> file.isDirectory() && name.startsWith(prefix)))) {
        final String name = directory.getName();
        loaders.submit(() -> {
            try {
                ConqueryMDC.setLocation(directory.toString());
                if (!environmentHasStores(directory, storesToTest)) {
                    log.warn("No valid WorkerStorage found.");
                    return;
                }
                T namespacedStorage = creator.apply(name);
                namespacedStorage.openStores(this);
                log.debug("BEGIN reading Storage");
                namespacedStorage.loadData();
                storages.add(namespacedStorage);
            } catch (Exception e) {
                log.error("Failed reading Storage", e);
            } finally {
                log.debug("DONE reading Storage");
                ConqueryMDC.clearLocation();
            }
        });
    }
    loaders.shutdown();
    while (!loaders.awaitTermination(1, TimeUnit.MINUTES)) {
        log.debug("Waiting for Worker storages to load. {} are already finished.", storages.size());
    }
    log.info("All WorkerStores loaded: {}", storages);
    return storages;
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Dictionary(com.bakdata.conquery.models.dictionary.Dictionary) WorkerStorage(com.bakdata.conquery.io.storage.WorkerStorage) SneakyThrows(lombok.SneakyThrows) MultimapBuilder(com.google.common.collect.MultimapBuilder) IId(com.bakdata.conquery.models.identifiable.ids.IId) EntityIdMap(com.bakdata.conquery.models.identifiable.mapping.EntityIdMap) Import(com.bakdata.conquery.models.datasets.Import) Environment(jetbrains.exodus.env.Environment) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Valid(javax.validation.Valid) CachedStore(com.bakdata.conquery.io.storage.xodus.stores.CachedStore) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) ToString(lombok.ToString) WeakCachedStore(com.bakdata.conquery.io.storage.xodus.stores.WeakCachedStore) XodusStore(com.bakdata.conquery.io.storage.xodus.stores.XodusStore) Path(java.nio.file.Path) InternalOnly(com.bakdata.conquery.io.jackson.InternalOnly) BiMap(com.google.common.collect.BiMap) Bucket(com.bakdata.conquery.models.events.Bucket) BigStore(com.bakdata.conquery.io.storage.xodus.stores.BigStore) NamespacedStorage(com.bakdata.conquery.io.storage.NamespacedStorage) CPSType(com.bakdata.conquery.io.cps.CPSType) With(lombok.With) NonNull(lombok.NonNull) Collection(java.util.Collection) Table(com.bakdata.conquery.models.datasets.Table) FormConfig(com.bakdata.conquery.models.forms.configs.FormConfig) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) Set(java.util.Set) Validator(javax.validation.Validator) Min(javax.validation.constraints.Min) NotNull(javax.validation.constraints.NotNull) User(com.bakdata.conquery.models.auth.entities.User) Executors(java.util.concurrent.Executors) Sets(com.google.common.collect.Sets) Dataset(com.bakdata.conquery.models.datasets.Dataset) Objects(java.util.Objects) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription) List(java.util.List) FileUtil(com.bakdata.conquery.util.io.FileUtil) Slf4j(lombok.extern.slf4j.Slf4j) CBlock(com.bakdata.conquery.models.events.CBlock) Jackson(com.bakdata.conquery.io.jackson.Jackson) Queue(java.util.Queue) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) SerializingStore(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IdentifiableStore(com.bakdata.conquery.io.storage.IdentifiableStore) Setter(lombok.Setter) Getter(lombok.Getter) Environments(jetbrains.exodus.env.Environments) Multimap(com.google.common.collect.Multimap) StoreMappings(com.bakdata.conquery.io.storage.StoreMappings) Function(java.util.function.Function) StoreInfo(com.bakdata.conquery.io.storage.xodus.stores.StoreInfo) Duration(io.dropwizard.util.Duration) SingletonStore(com.bakdata.conquery.io.storage.xodus.stores.SingletonStore) Multimaps(com.google.common.collect.Multimaps) HashSet(java.util.HashSet) Injectable(com.bakdata.conquery.io.jackson.Injectable) NamespaceStorage(com.bakdata.conquery.io.storage.NamespaceStorage) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) WorkerInformation(com.bakdata.conquery.models.worker.WorkerInformation) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ManagerNode(com.bakdata.conquery.commands.ManagerNode) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) Group(com.bakdata.conquery.models.auth.entities.Group) ConqueryMDC(com.bakdata.conquery.util.io.ConqueryMDC) ShardNode(com.bakdata.conquery.commands.ShardNode) WorkerToBucketsMap(com.bakdata.conquery.models.worker.WorkerToBucketsMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) File(java.io.File) Store(com.bakdata.conquery.io.storage.Store) TimeUnit(java.util.concurrent.TimeUnit) HashBiMap(com.google.common.collect.HashBiMap) StructureNode(com.bakdata.conquery.models.datasets.concepts.StructureNode) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) AllArgsConstructor(lombok.AllArgsConstructor) NoArgsConstructor(lombok.NoArgsConstructor) ExecutorService(java.util.concurrent.ExecutorService) ToString(lombok.ToString) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) File(java.io.File) IOException(java.io.IOException)

Aggregations

WorkerStorage (com.bakdata.conquery.io.storage.WorkerStorage)3 MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ManagerNode (com.bakdata.conquery.commands.ManagerNode)1 ShardNode (com.bakdata.conquery.commands.ShardNode)1 CPSType (com.bakdata.conquery.io.cps.CPSType)1 Injectable (com.bakdata.conquery.io.jackson.Injectable)1 InternalOnly (com.bakdata.conquery.io.jackson.InternalOnly)1 Jackson (com.bakdata.conquery.io.jackson.Jackson)1 IdentifiableStore (com.bakdata.conquery.io.storage.IdentifiableStore)1 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)1 ModificationShieldedWorkerStorage (com.bakdata.conquery.io.storage.ModificationShieldedWorkerStorage)1 NamespaceStorage (com.bakdata.conquery.io.storage.NamespaceStorage)1 NamespacedStorage (com.bakdata.conquery.io.storage.NamespacedStorage)1 Store (com.bakdata.conquery.io.storage.Store)1 StoreMappings (com.bakdata.conquery.io.storage.StoreMappings)1 BigStore (com.bakdata.conquery.io.storage.xodus.stores.BigStore)1 CachedStore (com.bakdata.conquery.io.storage.xodus.stores.CachedStore)1 SerializingStore (com.bakdata.conquery.io.storage.xodus.stores.SerializingStore)1 SingletonStore (com.bakdata.conquery.io.storage.xodus.stores.SingletonStore)1