示例#1
0
  private Pair<Map<String, String>, /*was it created now?*/ Boolean> getOrCreateIndexConfig(
      Class<? extends PropertyContainer> cls,
      String indexName,
      Map<String, String> suppliedConfig) {
    Pair<Map<String, String>, Boolean> result =
        findIndexConfig(cls, indexName, suppliedConfig, config.getParams());
    boolean createdNow = false;
    if (result.other()) { // Ok, we need to create this config
      synchronized (this) { // Were we the first ones to get here?
        Map<String, String> existing = indexStore.get(cls, indexName);
        if (existing != null) {
          // No, someone else made it before us, cool
          assertConfigMatches(
              getIndexProvider(existing.get(PROVIDER)), indexName, existing, result.first());
          return Pair.of(result.first(), false);
        }

        // We were the first one here, let's create this config
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        try {
          executorService.submit(new IndexCreatorJob(cls, indexName, result.first())).get();
          indexStore.set(cls, indexName, result.first());
          createdNow = true;
        } catch (ExecutionException ex) {
          throw new TransactionFailureException(
              "Index creation failed for " + indexName + ", " + result.first(), ex.getCause());
        } catch (InterruptedException ex) {
          Thread.interrupted();
        } finally {
          executorService.shutdownNow();
        }
      }
    }
    return Pair.of(result.first(), createdNow);
  }
示例#2
0
 private void removeProvidersFromIndexDbFile(File storeDir) {
   IndexStore indexStore = new IndexStore(storeDir.getPath());
   for (Class<? extends PropertyContainer> cls : new Class[] {Node.class, Relationship.class}) {
     for (String name : indexStore.getNames(cls)) {
       Map<String, String> config = indexStore.get(cls, name);
       config = new HashMap<String, String>(config);
       config.remove(IndexManager.PROVIDER);
       indexStore.set(Node.class, name, config);
     }
   }
 }
 private Map<String, String> config(
     Class<? extends PropertyContainer> cls, String indexName, Map<String, String> config) {
   // TODO Doesn't look right
   if (config != null) {
     config =
         MapUtil.stringMap(
             new HashMap<String, String>(config),
             "provider",
             BerkeleyDbIndexImplementation.SERVICE_NAME);
     indexStore.setIfNecessary(cls, indexName, config);
     return config;
   } else {
     return indexStore.get(cls, indexName);
   }
 }
示例#4
0
  private Pair<Map<String, String>, Boolean /*true=needs to be set*/> findIndexConfig(
      Class<? extends PropertyContainer> cls,
      String indexName,
      Map<String, String> suppliedConfig,
      Map<?, ?> dbConfig) {
    // Check stored config (has this index been created previously?)
    Map<String, String> storedConfig = indexStore.get(cls, indexName);
    if (storedConfig != null && suppliedConfig == null) {
      // Fill in "provider" if not already filled in, backwards compatibility issue
      Map<String, String> newConfig =
          injectDefaultProviderIfMissing(cls, indexName, dbConfig, storedConfig);
      if (newConfig != storedConfig) {
        indexStore.set(cls, indexName, newConfig);
      }
      return Pair.of(newConfig, Boolean.FALSE);
    }

    Map<String, String> configToUse = suppliedConfig;

    // Check db config properties for provider
    String provider = null;
    IndexImplementation indexProvider = null;
    if (configToUse == null) {
      provider = getDefaultProvider(indexName, dbConfig);
      configToUse = MapUtil.stringMap(PROVIDER, provider);
    } else {
      provider = configToUse.get(PROVIDER);
      provider = provider == null ? getDefaultProvider(indexName, dbConfig) : provider;
    }
    indexProvider = getIndexProvider(provider);
    configToUse = indexProvider.fillInDefaults(configToUse);
    configToUse = injectDefaultProviderIfMissing(cls, indexName, dbConfig, configToUse);

    // Do they match (stored vs. supplied)?
    if (storedConfig != null) {
      assertConfigMatches(indexProvider, indexName, storedConfig, suppliedConfig);
      // Fill in "provider" if not already filled in, backwards compatibility issue
      Map<String, String> newConfig =
          injectDefaultProviderIfMissing(cls, indexName, dbConfig, storedConfig);
      if (newConfig != storedConfig) {
        indexStore.set(cls, indexName, newConfig);
      }
      configToUse = newConfig;
    }

    boolean needsToBeSet = !indexStore.has(cls, indexName);
    return Pair.of(Collections.unmodifiableMap(configToUse), needsToBeSet);
  }
示例#5
0
 @Override
 public String setConfiguration(
     Index<? extends PropertyContainer> index, String key, String value) {
   assertLegalConfigKey(key);
   Map<String, String> config = getMutableConfig(index);
   String oldValue = config.put(key, value);
   indexStore.set(index.getEntityType(), index.getName(), config);
   return oldValue;
 }
示例#6
0
 @Override
 public Map<String, String> getConfiguration(Index<? extends PropertyContainer> index) {
   Map<String, String> config = indexStore.get(index.getEntityType(), index.getName());
   if (config == null) {
     throw new NotFoundException(
         "No " + index.getEntityType().getSimpleName() + " index '" + index.getName() + "' found");
   }
   return config;
 }
示例#7
0
 @Override
 public String removeConfiguration(Index<? extends PropertyContainer> index, String key) {
   assertLegalConfigKey(key);
   Map<String, String> config = getMutableConfig(index);
   String value = config.remove(key);
   if (value != null) {
     indexStore.set(index.getEntityType(), index.getName(), config);
   }
   return value;
 }
示例#8
0
 Index<Node> getOrCreateNodeIndex(String indexName, Map<String, String> customConfiguration) {
   Pair<Map<String, String>, Boolean> config =
       getOrCreateIndexConfig(Node.class, indexName, customConfiguration);
   try {
     return getIndexProvider(config.first().get(PROVIDER)).nodeIndex(indexName, config.first());
   } catch (RuntimeException e) {
     if (config.other()) {
       indexStore.remove(Node.class, indexName);
     }
     throw e;
   }
 }
示例#9
0
  BatchInserterImpl(
      String storeDir, FileSystemAbstraction fileSystem, Map<String, String> stringParams) {
    this.fileSystem = fileSystem;
    this.storeDir = new File(FileUtils.fixSeparatorsInPath(storeDir));

    rejectAutoUpgrade(stringParams);
    msgLog = StringLogger.loggerDirectory(fileSystem, this.storeDir);
    Map<String, String> params = getDefaultParams();
    params.put(GraphDatabaseSettings.use_memory_mapped_buffers.name(), Settings.FALSE);
    params.put(InternalAbstractGraphDatabase.Configuration.store_dir.name(), storeDir);
    params.putAll(stringParams);

    Config config = new Config(params, GraphDatabaseSettings.class);
    boolean dump = config.get(GraphDatabaseSettings.dump_configuration);
    this.idGeneratorFactory = new DefaultIdGeneratorFactory();

    StoreFactory sf =
        new StoreFactory(
            config,
            idGeneratorFactory,
            new DefaultWindowPoolFactory(),
            fileSystem,
            StringLogger.DEV_NULL,
            null);

    File store = fixPath(this.storeDir, sf);

    if (dump) {
      dumpConfiguration(params);
    }
    msgLog.logMessage(Thread.currentThread() + " Starting BatchInserter(" + this + ")");
    neoStore = sf.newNeoStore(store);
    if (!neoStore.isStoreOk()) {
      throw new IllegalStateException(storeDir + " store is not cleanly shutdown.");
    }
    neoStore.makeStoreOk();
    NameData[] indexes = getPropertyIndexStore().getNames(10000);
    indexHolder = new PropertyIndexHolder(indexes);
    NameData[] types = getRelationshipTypeStore().getNames(Integer.MAX_VALUE);
    typeHolder = new RelationshipTypeHolder(types);
    indexStore = new IndexStore(this.storeDir, fileSystem);
    indexStore.start();
  }
示例#10
0
 @Override
 public String[] relationshipIndexNames() {
   return indexStore.getNames(Relationship.class);
 }
示例#11
0
 @Override
 public boolean existsForRelationships(String indexName) {
   return indexStore.get(Relationship.class, indexName) != null;
 }
示例#12
0
 @Override
 public String[] nodeIndexNames() {
   return indexStore.getNames(Node.class);
 }
示例#13
0
 @Override
 public boolean existsForNodes(String indexName) {
   return indexStore.get(Node.class, indexName) != null;
 }
示例#14
0
 @Override
 public String[] relationshipIndexNames() {
   assertInTransaction();
   return indexStore.getNames(Relationship.class);
 }
示例#15
0
 @Override
 public String[] nodeIndexNames() {
   assertInTransaction();
   return indexStore.getNames(Node.class);
 }
示例#16
0
 @Override
 public boolean existsForNodes(String indexName) {
   assertInTransaction();
   return indexStore.get(Node.class, indexName) != null;
 }