コード例 #1
0
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
  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
ファイル: TestMigration.java プロジェクト: huobao36/community
 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
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
  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
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
 @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
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
 @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
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
 @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
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
 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.java プロジェクト: kov4l/neo4j
  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
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
 @Override
 public String[] relationshipIndexNames() {
   return indexStore.getNames(Relationship.class);
 }
コード例 #11
0
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
 @Override
 public boolean existsForRelationships(String indexName) {
   return indexStore.get(Relationship.class, indexName) != null;
 }
コード例 #12
0
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
 @Override
 public String[] nodeIndexNames() {
   return indexStore.getNames(Node.class);
 }
コード例 #13
0
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
 @Override
 public boolean existsForNodes(String indexName) {
   return indexStore.get(Node.class, indexName) != null;
 }
コード例 #14
0
ファイル: IndexManagerImpl.java プロジェクト: radekzak/neo4j
 @Override
 public String[] relationshipIndexNames() {
   assertInTransaction();
   return indexStore.getNames(Relationship.class);
 }
コード例 #15
0
ファイル: IndexManagerImpl.java プロジェクト: radekzak/neo4j
 @Override
 public String[] nodeIndexNames() {
   assertInTransaction();
   return indexStore.getNames(Node.class);
 }
コード例 #16
0
ファイル: IndexManagerImpl.java プロジェクト: radekzak/neo4j
 @Override
 public boolean existsForNodes(String indexName) {
   assertInTransaction();
   return indexStore.get(Node.class, indexName) != null;
 }