-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
StorageEngine.java
154 lines (138 loc) · 7.11 KB
/
StorageEngine.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
/*
* 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.storageengine.api;
import java.util.Collection;
import java.util.stream.Stream;
import org.neo4j.internal.diagnostics.DiagnosticsManager;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException;
import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException;
import org.neo4j.storageengine.api.lock.ResourceLocker;
import org.neo4j.storageengine.api.txstate.ReadableTransactionState;
import org.neo4j.storageengine.api.txstate.TxStateVisitor;
/**
* A StorageEngine provides the functionality to durably store data, and read it back.
*/
public interface StorageEngine
{
/**
* Creates a new {@link StorageReader} for reading committed data from the underlying storage.
* The returned instance is intended to be used by one transaction at a time, although can and should be reused
* for multiple transactions.
*
* @return an interface for accessing data previously
* {@link #apply(CommandsToApply, TransactionApplicationMode) applied} to this storage.
*/
StorageReader newReader();
/**
* @return a new {@link CommandCreationContext} meant to be kept for multiple calls to
* {@link #createCommands(Collection, ReadableTransactionState, StorageReader, ResourceLocker, long, TxStateVisitor.Decorator)}.
* Must be {@link CommandCreationContext#close() closed} after used, before being discarded.
*/
CommandCreationContext allocateCommandCreationContext();
/**
* Generates a list of {@link StorageCommand commands} representing the changes in the given transaction state
* ({@code state}.
* The returned commands can be used to form {@link CommandsToApply} batches, which can be applied to this
* storage using {@link #apply(CommandsToApply, TransactionApplicationMode)}.
* The reason this is separated like this is that the generated commands can be used for other things
* than applying to storage, f.ex replicating to another storage engine.
* @param target {@link Collection} to put {@link StorageCommand commands} into.
* @param state {@link ReadableTransactionState} representing logical store changes to generate commands for.
* @param storageReader {@link StorageReader} to use for reading store state during creation of commands.
* @param locks {@link ResourceLocker} can grab additional locks.
* This locks client still have the potential to acquire more locks at this point.
* TODO we should try to get rid of this locking mechanism during creation of commands
* The reason it's needed is that some relationship changes in the record storage engine
* needs to lock prev/next relationships and these changes happens when creating commands
* The EntityLocker interface is a subset of Locks.Client interface, just to fit in while it's here.
* @param lastTransactionIdWhenStarted transaction id which was seen as last committed when this
* transaction started, i.e. before any changes were made and before any data was read.
* TODO Transitional (Collection), might be {@link Stream} or whatever.
* @param additionalTxStateVisitor any additional tx state visitor decoration.
*
* @throws TransactionFailureException if command generation fails or some prerequisite of some command
* didn't validate, for example if trying to delete a node that still has relationships.
* @throws CreateConstraintFailureException if this transaction was set to create a constraint and that failed.
* @throws ConstraintValidationException if this transaction was set to create a constraint
* and some data violates that constraint.
*/
void createCommands(
Collection<StorageCommand> target,
ReadableTransactionState state,
StorageReader storageReader,
ResourceLocker locks,
long lastTransactionIdWhenStarted,
TxStateVisitor.Decorator additionalTxStateVisitor )
throws TransactionFailureException, CreateConstraintFailureException, ConstraintValidationException;
/**
* Apply a batch of groups of commands to this storage.
*
* @param batch batch of groups of commands to apply to storage.
* @param mode {@link TransactionApplicationMode} when applying.
* @throws Exception if an error occurs during application.
*/
void apply( CommandsToApply batch, TransactionApplicationMode mode ) throws Exception;
/**
* @return a {@link CommandReaderFactory} capable of returning {@link CommandReader commands readers}
* for specific log entry versions.
*/
CommandReaderFactory commandReaderFactory();
/**
* Flushes and forces all changes down to underlying storage. This is a blocking call and when it returns
* all changes applied to this storage engine will be durable.
* @param limiter The {@link IOLimiter} used to moderate the rate of IO caused by the flush process.
*/
void flushAndForce( IOLimiter limiter );
/**
* Registers diagnostics about the storage onto {@link DiagnosticsManager}.
*
* @param diagnosticsManager {@link DiagnosticsManager} to register diagnostics at.
*/
void registerDiagnostics( DiagnosticsManager diagnosticsManager );
/**
* Force close all opened resources. This may be called during startup if there's a failure
* during recovery or similar.
*/
void forceClose();
/**
* Startup process have reached the conclusion that recovery is required. Make the necessary
* preparations to be ready for recovering transactions.
*/
void prepareForRecoveryRequired();
/**
* @return a {@link Collection} of {@link StoreFileMetadata} containing metadata about all store files managed by
* this {@link StorageEngine}.
*/
Collection<StoreFileMetadata> listStorageFiles();
/**
* @return the {@link StoreId} of the underlying store.
*/
StoreId getStoreId();
// ====================================================================
// All these methods below are temporary while in the process of
// creating this API, take little notice to them, as they will go away
// ====================================================================
@Deprecated
void loadSchemaCache();
@Deprecated
void clearBufferedIds();
}