-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
EditionModule.java
291 lines (247 loc) · 11.7 KB
/
EditionModule.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
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.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.graphdb.factory.module;
import java.io.File;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.neo4j.dbms.database.DatabaseManager;
import org.neo4j.dmbs.database.DefaultDatabaseManager;
import org.neo4j.graphdb.facade.GraphDatabaseFacadeFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.Service;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.fs.watcher.RestartableFileSystemWatcher;
import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.kernel.api.net.NetworkConnectionTracker;
import org.neo4j.kernel.api.security.AuthManager;
import org.neo4j.kernel.api.security.SecurityModule;
import org.neo4j.kernel.api.security.UserManagerSupplier;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.api.CommitProcessFactory;
import org.neo4j.kernel.impl.api.SchemaWriteGuard;
import org.neo4j.kernel.impl.constraints.ConstraintSemantics;
import org.neo4j.kernel.impl.core.TokenHolders;
import org.neo4j.kernel.impl.factory.AccessCapability;
import org.neo4j.kernel.impl.factory.DatabaseInfo;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacade;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.proc.ProcedureConfig;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.BufferedIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.DefaultIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController;
import org.neo4j.kernel.impl.store.id.BufferingIdGeneratorFactory;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.store.id.IdReuseEligibility;
import org.neo4j.kernel.impl.store.id.configuration.IdTypeConfigurationProvider;
import org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory;
import org.neo4j.kernel.impl.transaction.stats.DatabaseTransactionStats;
import org.neo4j.kernel.impl.transaction.stats.TransactionCounters;
import org.neo4j.kernel.impl.util.Dependencies;
import org.neo4j.kernel.impl.util.DependencySatisfier;
import org.neo4j.kernel.impl.util.watcher.DefaultFileDeletionEventListener;
import org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService;
import org.neo4j.kernel.impl.util.watcher.FileSystemWatcherService;
import org.neo4j.logging.Log;
import org.neo4j.logging.Logger;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.udc.UsageData;
import org.neo4j.udc.UsageDataKeys;
import org.neo4j.util.FeatureToggles;
import static org.neo4j.kernel.impl.proc.temporal.TemporalFunction.registerTemporalFunctions;
/**
* Edition module for {@link GraphDatabaseFacadeFactory}. Implementations of this class
* need to create all the services that would be specific for a particular edition of the database.
*/
public abstract class EditionModule
{
// This resided in RecordStorageEngine prior to 3.3
private static final boolean safeIdBuffering = FeatureToggles.flag(
EditionModule.class, "safeIdBuffering", true );
public IdGeneratorFactory idGeneratorFactory;
public IdTypeConfigurationProvider idTypeConfigurationProvider;
public Supplier<TokenHolders> tokenHoldersSupplier;
public Supplier<Locks> locksSupplier;
public Function<Locks, StatementLocksFactory> statementLocksFactoryProvider;
public CommitProcessFactory commitProcessFactory;
public long transactionStartTimeout;
public TransactionHeaderInformationFactory headerInformationFactory;
public SchemaWriteGuard schemaWriteGuard;
public ConstraintSemantics constraintSemantics;
public AccessCapability accessCapability;
public IOLimiter ioLimiter;
public IdReuseEligibility eligibleForIdReuse;
public Function<File, FileSystemWatcherService> watcherServiceFactory;
public IdController idController;
public AuthManager authManager;
public UserManagerSupplier userManagerSupplier;
public NetworkConnectionTracker connectionTracker;
private final DatabaseTransactionStats databaseStatistics = new DatabaseTransactionStats();
protected FileSystemWatcherService createFileSystemWatcherService( FileSystemAbstraction fileSystem, File databaseDirectory,
LogService logging, JobScheduler jobScheduler, Config config, Predicate<String> fileNameFilter )
{
if ( !config.get( GraphDatabaseSettings.filewatcher_enabled ) )
{
Log log = logging.getInternalLog( getClass() );
log.info( "File watcher disabled by configuration." );
return FileSystemWatcherService.EMPTY_WATCHER;
}
try
{
RestartableFileSystemWatcher watcher = new RestartableFileSystemWatcher( fileSystem.fileWatcher() );
watcher.addFileWatchEventListener( new DefaultFileDeletionEventListener( logging, fileNameFilter ) );
watcher.watch( databaseDirectory );
// register to watch database dir parent folder to see when database dir removed
watcher.watch( databaseDirectory.getParentFile() );
return new DefaultFileSystemWatcherService( jobScheduler, watcher );
}
catch ( Exception e )
{
Log log = logging.getInternalLog( getClass() );
log.warn( "Can not create file watcher for current file system. File monitoring capabilities for store " +
"files will be disabled.", e );
return FileSystemWatcherService.EMPTY_WATCHER;
}
}
public void registerProcedures( Procedures procedures, ProcedureConfig procedureConfig ) throws KernelException
{
procedures.registerProcedure( org.neo4j.kernel.builtinprocs.BuiltInProcedures.class );
procedures.registerProcedure( org.neo4j.kernel.builtinprocs.TokenProcedures.class );
procedures.registerProcedure( org.neo4j.kernel.builtinprocs.BuiltInDbmsProcedures.class );
procedures.registerBuiltInFunctions( org.neo4j.kernel.builtinprocs.BuiltInFunctions.class );
registerTemporalFunctions( procedures, procedureConfig );
registerEditionSpecificProcedures( procedures );
}
protected abstract void registerEditionSpecificProcedures( Procedures procedures ) throws KernelException;
protected void publishEditionInfo( UsageData sysInfo, DatabaseInfo databaseInfo, Config config )
{
sysInfo.set( UsageDataKeys.edition, databaseInfo.edition );
sysInfo.set( UsageDataKeys.operationalMode, databaseInfo.operationalMode );
config.augment( GraphDatabaseSettings.editionName, databaseInfo.edition.toString() );
}
public DatabaseManager createDatabaseManager( GraphDatabaseFacade graphDatabaseFacade, PlatformModule platform, EditionModule edition,
Procedures procedures, Logger msgLog )
{
return new DefaultDatabaseManager( platform, edition, procedures, msgLog, graphDatabaseFacade );
}
public abstract void createSecurityModule( PlatformModule platformModule, Procedures procedures );
protected static SecurityModule setupSecurityModule( PlatformModule platformModule, Log log, Procedures procedures,
String key )
{
for ( SecurityModule candidate : Service.load( SecurityModule.class ) )
{
if ( candidate.matches( key ) )
{
try
{
candidate.setup( new SecurityModule.Dependencies()
{
@Override
public LogService logService()
{
return platformModule.logging;
}
@Override
public Config config()
{
return platformModule.config;
}
@Override
public Procedures procedures()
{
return procedures;
}
@Override
public JobScheduler scheduler()
{
return platformModule.jobScheduler;
}
@Override
public FileSystemAbstraction fileSystem()
{
return platformModule.fileSystem;
}
@Override
public DependencySatisfier dependencySatisfier()
{
return platformModule.dependencies;
}
} );
return candidate;
}
catch ( Exception e )
{
String errorMessage = "Failed to load security module.";
log.error( errorMessage );
throw new RuntimeException( errorMessage, e );
}
}
}
String errorMessage = "Failed to load security module with key '" + key + "'.";
log.error( errorMessage );
throw new IllegalArgumentException( errorMessage );
}
protected NetworkConnectionTracker createConnectionTracker()
{
return NetworkConnectionTracker.NO_OP;
}
protected void createIdComponents( PlatformModule platformModule, Dependencies dependencies, IdGeneratorFactory
editionIdGeneratorFactory )
{
IdGeneratorFactory factory = editionIdGeneratorFactory;
if ( safeIdBuffering )
{
BufferingIdGeneratorFactory bufferingIdGeneratorFactory =
new BufferingIdGeneratorFactory( factory, eligibleForIdReuse, idTypeConfigurationProvider );
idController = createBufferedIdController( bufferingIdGeneratorFactory, platformModule.jobScheduler );
factory = bufferingIdGeneratorFactory;
}
else
{
idController = createDefaultIdController();
}
this.idGeneratorFactory = factory;
}
private BufferedIdController createBufferedIdController( BufferingIdGeneratorFactory idGeneratorFactory,
JobScheduler scheduler )
{
return new BufferedIdController( idGeneratorFactory, scheduler );
}
protected DefaultIdController createDefaultIdController()
{
return new DefaultIdController();
}
public void createDatabases( DatabaseManager databaseManager, Config config )
{
databaseManager.createDatabase( config.get( GraphDatabaseSettings.active_database ) );
}
public DatabaseTransactionStats createTransactionMonitor()
{
return databaseStatistics;
}
public TransactionCounters globalTransactionCounter()
{
return databaseStatistics;
}
}