forked from eldersantos/community
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Config.java
568 lines (506 loc) · 20.3 KB
/
Config.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
/**
* Copyright (c) 2002-2012 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.transaction.TransactionManager;
import static java.util.regex.Pattern.quote;
import org.neo4j.helpers.Args;
import org.neo4j.helpers.collection.PrefetchingIterator;
import org.neo4j.kernel.impl.annotations.Documented;
import org.neo4j.kernel.impl.core.GraphDbModule;
import org.neo4j.kernel.impl.core.KernelPanicEventGenerator;
import org.neo4j.kernel.impl.core.LastCommittedTxIdSetter;
import org.neo4j.kernel.impl.core.LockReleaser;
import org.neo4j.kernel.impl.core.RelationshipTypeCreator;
import org.neo4j.kernel.impl.core.RelationshipTypeHolder;
import org.neo4j.kernel.impl.core.TxEventSyncHookFactory;
import org.neo4j.kernel.impl.index.IndexStore;
import org.neo4j.kernel.impl.nioneo.store.FileSystemAbstraction;
import org.neo4j.kernel.impl.nioneo.store.StoreId;
import org.neo4j.kernel.impl.persistence.IdGenerator;
import org.neo4j.kernel.impl.persistence.IdGeneratorModule;
import org.neo4j.kernel.impl.persistence.PersistenceModule;
import org.neo4j.kernel.impl.transaction.LockManager;
import org.neo4j.kernel.impl.transaction.TxHook;
import org.neo4j.kernel.impl.transaction.TxModule;
import org.neo4j.kernel.impl.transaction.xaframework.TxIdGenerator;
import org.neo4j.kernel.impl.util.StringLogger;
import org.neo4j.kernel.info.DiagnosticsManager;
import org.neo4j.kernel.info.DiagnosticsPhase;
import org.neo4j.kernel.info.DiagnosticsProvider;
/**
* A non-standard configuration object.
*/
public class Config implements DiagnosticsProvider
{
static final String NIO_NEO_DB_CLASS = "org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource";
public static final String DEFAULT_DATA_SOURCE_NAME = "nioneodb";
static final String LUCENE_DS_CLASS = "org.neo4j.index.lucene.LuceneDataSource";
static final String LUCENE_FULLTEXT_DS_CLASS = "org.neo4j.index.lucene.LuceneFulltextDataSource";
/**
* Tell Neo4j to use memory mapped buffers for accessing the native storage
* layer
*/
@Documented
public static final String USE_MEMORY_MAPPED_BUFFERS = "use_memory_mapped_buffers";
/** Print out the effective Neo4j configuration after startup */
@Documented
public static final String DUMP_CONFIGURATION = "dump_configuration";
/**
* Make Neo4j keep the logical transaction logs for being able to backup the
* database
*/
@Documented
public static final String KEEP_LOGICAL_LOGS = "keep_logical_logs";
/** Enable a remote shell server which shell clients can log in to */
@Documented
public static final String ENABLE_REMOTE_SHELL = "enable_remote_shell";
/** Enable a support for running online backups */
@Documented
public static final String ENABLE_ONLINE_BACKUP = "enable_online_backup";
/** Mark this database as a backup slave. */
@Documented
public static final String BACKUP_SLAVE = "backup_slave";
/** Only allow read operations from this Neo4j instance. */
@Documented
public static final String READ_ONLY = "read_only";
/** Relative path for where the Neo4j storage directory is located */
@Documented
public static final String STORAGE_DIRECTORY = "store_dir";
/**
* Use a quick approach for rebuilding the ID generators. This give quicker
* recovery time, but will limit the ability to reuse the space of deleted
* entities.
*/
@Documented
public static final String REBUILD_IDGENERATORS_FAST = "rebuild_idgenerators_fast";
/** The size to allocate for memory mapping the node store */
@Documented
public static final String NODE_STORE_MMAP_SIZE = "neostore.nodestore.db.mapped_memory";
/** The size to allocate for memory mapping the array property store */
@Documented
public static final String ARRAY_PROPERTY_STORE_MMAP_SIZE = "neostore.propertystore.db.arrays.mapped_memory";
/**
* The size to allocate for memory mapping the store for property key
* strings
*/
@Documented
public static final String PROPERTY_INDEX_KEY_STORE_MMAP_SIZE = "neostore.propertystore.db.index.keys.mapped_memory";
/**
* The size to allocate for memory mapping the store for property key
* indexes
*/
@Documented
public static final String PROPERTY_INDEX_STORE_MMAP_SIZE = "neostore.propertystore.db.index.mapped_memory";
/** The size to allocate for memory mapping the property value store */
@Documented
public static final String PROPERTY_STORE_MMAP_SIZE = "neostore.propertystore.db.mapped_memory";
/** The size to allocate for memory mapping the string property store */
@Documented
public static final String STRING_PROPERTY_STORE_MMAP_SIZE = "neostore.propertystore.db.strings.mapped_memory";
/** The size to allocate for memory mapping the relationship store */
@Documented
public static final String RELATIONSHIP_STORE_MMAP_SIZE = "neostore.relationshipstore.db.mapped_memory";
/** Relative path for where the Neo4j logical log is located */
@Documented
public static final String LOGICAL_LOG = "logical_log";
/** Relative path for where the Neo4j storage information file is located */
@Documented
public static final String NEO_STORE = "neo_store";
/**
* The type of cache to use for nodes and relationships, one of [weak, soft,
* none, array]
*/
@Documented
public static final String CACHE_TYPE = "cache_type";
/**
* The amount of memory to use for the node cache (when using the 'array' cache).
*/
@Documented
public static final String NODE_ARRAY_CACHE_SIZE = "node_cache_size";
/**
* The amount of memory to use for the relationship cache (when using the 'array' cache).
*/
@Documented
public static final String RELATIONSHIP_ARRAY_CACHE_SIZE = "relationship_cache_size";
/**
* The fraction of the heap (1%-10%) to use for the base array in the node cache (when using the 'array' cache).
*/
@Documented
public static final String NODE_ARRAY_CACHE_ARRAY_FRACTION = "node_cache_array_fraction";
/**
* The fraction of the heap (1%-10%) to use for the base array in the relationship cache (when using the 'array' cache).
*/
@Documented
public static final String RELATIONSHIP_ARRAY_CACHE_ARRAY_FRACTION = "relationship_cache_array_fraction";
/**
* The minimal time that must pass in between logging statistics from the cache (when using the 'array' cache).
* Default unit is seconds, suffix with 's', 'm', or 'ms' to have the unit be seconds, minutes or milliseconds respectively.
*/
@Documented
public static final String ARRAY_CACHE_MIN_LOG_INTERVAL = "array_cache_min_log_interval";
/**
* The name of the Transaction Manager service to use as defined in the TM
* service provider constructor, defaults to native.
*/
@Documented
public static final String TXMANAGER_IMPLEMENTATION = "tx_manager_impl";
/**
* Determines whether any TransactionInterceptors loaded will intercept
* prepared transactions before they reach the logical log. Defaults to
* false.
*/
@Documented
public static final String INTERCEPT_COMMITTING_TRANSACTIONS = "intercept_committing_transactions";
/**
* Determines whether any TransactionInterceptors loaded will intercept
* externally received transactions (e.g. in HA) before they reach the
* logical log and are applied to the store. Defaults to false.
*/
@Documented
public static final String INTERCEPT_DESERIALIZED_TRANSACTIONS = "intercept_deserialized_transactions";
/**
* Boolean (one of true,false) defining whether to allow a store upgrade
* in case the current version of the database starts against an older store
* version. Setting this to true does not guarantee successful upgrade, just
* allows an attempt at it.
*/
@Documented
public static final String ALLOW_STORE_UPGRADE = "allow_store_upgrade";
public static final String STRING_BLOCK_SIZE = "string_block_size";
public static final String ARRAY_BLOCK_SIZE = "array_block_size";
/**
* A list of property names (comma separated) that will be indexed by
* default.
* This applies to Nodes only.
*/
@Documented
public static final String NODE_KEYS_INDEXABLE = "node_keys_indexable";
/**
* A list of property names (comma separated) that will be indexed by
* default.
* This applies to Relationships only.
*/
@Documented
public static final String RELATIONSHIP_KEYS_INDEXABLE = "relationship_keys_indexable";
/**
* Boolean value (one of true, false) that controls the auto indexing
* feature for nodes. Setting to false shuts it down unconditionally,
* while true enables it for every property, subject to restrictions
* in the configuration.
* The default is false.
*/
@Documented
public static final String NODE_AUTO_INDEXING = "node_auto_indexing";
/**
* Boolean value (one of true, false) that controls the auto indexing
* feature for relationships. Setting to false shuts it down
* unconditionally, while true enables it for every property, subject
* to restrictions in the configuration.
* The default is false.
*/
@Documented
public static final String RELATIONSHIP_AUTO_INDEXING = "relationship_auto_indexing";
/**
* Integer value that sets the maximum number of open lucene index searchers.
* The default is Integer.MAX_VALUE
*/
@Documented
public static final String LUCENE_SEARCHER_CACHE_SIZE = "lucene_searcher_cache_size";
/**
* Integer value that sets the maximum number of open lucene index writers.
* The default is Integer.MAX_VALUE
*/
@Documented
public static final String LUCENE_WRITER_CACHE_SIZE = "lucene_writer_cache_size";
/**
* Amount of time in ms the GC monitor thread will wait before taking another measurement.
* Default is 100 ms.
*/
@Documented
public static final String GC_MONITOR_WAIT_TIME = "gc_monitor_wait_time";
/**
* The amount of time in ms the monitor thread has to be blocked before logging a message it was blocked.
* Default is 200ms
*/
@Documented
public static final String GC_MONITOR_THRESHOLD = "gc_monitor_threshold";
static final String LOAD_EXTENSIONS = "load_kernel_extensions";
private final TxModule txModule;
private final LockManager lockManager;
private final LockReleaser lockReleaser;
private final PersistenceModule persistenceModule;
private boolean create = false;
private String persistenceSourceName;
private final IdGeneratorModule idGeneratorModule;
private final GraphDbModule graphDbModule;
private final String storeDir;
private final IndexStore indexStore;
private final Map<Object, Object> params;
private final Map inputParams;
private final TxEventSyncHookFactory syncHookFactory;
private final RelationshipTypeCreator relTypeCreator;
private final boolean readOnly;
private final boolean ephemeral;
private final boolean backupSlave;
private final IdGeneratorFactory idGeneratorFactory;
private final TxIdGenerator txIdGenerator;
private final DiagnosticsManager diagnostics;
private final KernelPanicEventGenerator kpe;
Config( AbstractGraphDatabase graphDb, StoreId storeId,
Map<String, String> inputParams, KernelPanicEventGenerator kpe,
TxModule txModule, LockManager lockManager,
LockReleaser lockReleaser, IdGeneratorFactory idGeneratorFactory,
TxEventSyncHookFactory txSyncHookFactory,
RelationshipTypeCreator relTypeCreator, TxIdGenerator txIdGenerator,
LastCommittedTxIdSetter lastCommittedTxIdSetter,
FileSystemAbstraction fileSystem )
{
this.kpe = kpe;
this.storeDir = graphDb.getStoreDir();
this.inputParams = inputParams;
this.ephemeral = graphDb.isEphemeral();
// Get the default params and override with the user supplied values
this.params = getDefaultParams();
this.params.putAll( inputParams );
this.idGeneratorFactory = idGeneratorFactory;
this.relTypeCreator = relTypeCreator;
this.txIdGenerator = txIdGenerator;
this.txModule = txModule;
this.lockManager = lockManager;
this.lockReleaser = lockReleaser;
this.idGeneratorModule = new IdGeneratorModule( new IdGenerator() );
this.readOnly = Boolean.parseBoolean( (String) params.get( READ_ONLY ) );
this.backupSlave = Boolean.parseBoolean( (String) params.get( BACKUP_SLAVE ) );
this.syncHookFactory = txSyncHookFactory;
this.persistenceModule = new PersistenceModule();
this.params.put( FileSystemAbstraction.class, fileSystem );
graphDbModule = new GraphDbModule( graphDb, lockManager,
txModule.getTxManager(), idGeneratorModule.getIdGenerator(),
readOnly );
indexStore = new IndexStore( storeDir, fileSystem );
params.put( IndexStore.class, indexStore );
if ( storeId != null ) params.put( StoreId.class, storeId );
params.put( IdGeneratorFactory.class, idGeneratorFactory );
params.put( TxIdGenerator.class, txIdGenerator );
params.put( TransactionManager.class, txModule.getTxManager() );
params.put( LastCommittedTxIdSetter.class, lastCommittedTxIdSetter );
params.put( GraphDbModule.class, graphDbModule );
params.put( TxHook.class, txModule.getTxHook() );
params.put( StringLogger.class, graphDb.getMessageLog() );
params.put( DiagnosticsManager.class, this.diagnostics = new DiagnosticsManager( graphDb.getMessageLog() ) );
diagnostics.appendProvider( this );
}
public static Map<Object, Object> getDefaultParams()
{
Map<Object, Object> params = new HashMap<Object, Object>();
params.put( "neostore.nodestore.db.mapped_memory", "20M" );
params.put( "neostore.propertystore.db.mapped_memory", "90M" );
params.put( "neostore.propertystore.db.index.mapped_memory", "1M" );
params.put( "neostore.propertystore.db.index.keys.mapped_memory", "1M" );
params.put( "neostore.propertystore.db.strings.mapped_memory", "130M" );
params.put( "neostore.propertystore.db.arrays.mapped_memory", "130M" );
params.put( "neostore.relationshipstore.db.mapped_memory", "100M" );
// if on windows, default no memory mapping
if ( osIsWindows() )
{
params.put( Config.USE_MEMORY_MAPPED_BUFFERS, "false" );
}
else
{
// If not on win, default use memory mapping
params.put( Config.USE_MEMORY_MAPPED_BUFFERS, "true" );
}
params.put( NODE_AUTO_INDEXING, "false" );
params.put( RELATIONSHIP_AUTO_INDEXING, "false" );
return params;
}
public static boolean osIsWindows()
{
String nameOs = System.getProperty( "os.name" );
return nameOs.startsWith( "Windows" );
}
public static boolean osIsMacOS()
{
String nameOs = System.getProperty( "os.name" );
return nameOs.equalsIgnoreCase( "Mac OS X" );
}
void setPersistenceSource( String name, boolean create )
{
persistenceSourceName = name;
this.create = create;
}
String getPersistenceSource()
{
return persistenceSourceName;
}
boolean getCreatePersistenceSource()
{
return create;
}
public TxModule getTxModule()
{
return txModule;
}
public GraphDbModule getGraphDbModule()
{
return graphDbModule;
}
public PersistenceModule getPersistenceModule()
{
return persistenceModule;
}
public IdGeneratorModule getIdGeneratorModule()
{
return idGeneratorModule;
}
public LockManager getLockManager()
{
return lockManager;
}
public IndexStore getIndexStore()
{
return indexStore;
}
public LockReleaser getLockReleaser()
{
return lockReleaser;
}
public Map<Object, Object> getParams()
{
return this.params;
}
public boolean isReadOnly()
{
return readOnly;
}
public boolean isEphemeral()
{
return ephemeral;
}
boolean isBackupSlave()
{
return backupSlave;
}
Map<Object, Object> getInputParams()
{
return inputParams;
}
TxEventSyncHookFactory getSyncHookFactory()
{
return syncHookFactory;
}
public RelationshipTypeCreator getRelationshipTypeCreator()
{
return relTypeCreator;
}
public IdGeneratorFactory getIdGeneratorFactory()
{
return idGeneratorFactory;
}
public RelationshipTypeHolder getRelationshipTypeHolder()
{
return graphDbModule.getNodeManager().getRelationshipTypeHolder();
}
public static void dumpConfiguration( Map<?, ?> config )
{
for ( Object key : config.keySet() )
{
if ( key instanceof String )
{
Object value = config.get( key );
if ( value instanceof String )
{
System.out.println( key + "=" + value );
}
}
}
}
public static boolean configValueContainsMultipleParameters( String configValue )
{
return configValue != null && configValue.contains( "=" );
}
public static Args parseMapFromConfigValue( String name, String configValue )
{
Map<String, String> result = new HashMap<String, String>();
for ( String part : configValue.split( quote( "," ) ) )
{
String[] tokens = part.split( quote( "=" ) );
if ( tokens.length != 2 )
{
throw new RuntimeException( "Invalid configuration value '" + configValue +
"' for " + name + ". The format is [true/false] or [key1=value1,key2=value2...]" );
}
result.put( tokens[0], tokens[1] );
}
return new Args( result );
}
public static Object getFromConfig( Map<?, ?> config, Object key,
Object defaultValue )
{
Object result = config != null ? config.get( key ) : defaultValue;
return result != null ? result : defaultValue;
}
public DiagnosticsManager getDiagnosticsManager()
{
return diagnostics;
}
@Override
public String getDiagnosticsIdentifier()
{
return getClass().getName();
}
@Override
public void acceptDiagnosticsVisitor( Object visitor )
{
// nothing visits configuration
}
@Override
public void dump( DiagnosticsPhase phase, StringLogger log )
{
if ( phase.isInitialization() || phase.isExplicitlyRequested() )
{
log.logLongMessage( "Neo4j Kernel properties:", new PrefetchingIterator<String>()
{
final Iterator<Object> keys = params.keySet().iterator();
@Override
protected String fetchNextOrNull()
{
while ( keys.hasNext() )
{
Object key = keys.next();
if ( key instanceof String )
{
Object value = params.get( key );
return key + "=" + value;
}
}
return null;
}
}, true );
}
}
public KernelPanicEventGenerator getKernelPanicGenerator()
{
return kpe;
}
}