forked from voldemort/voldemort
/
StorageEngine.java
142 lines (128 loc) · 4.8 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
/*
* Copyright 2008-2013 LinkedIn, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package voldemort.store;
import java.util.List;
import voldemort.utils.ClosableIterator;
import voldemort.utils.Pair;
import voldemort.versioning.Versioned;
/**
* A base storage class which is actually responsible for data persistence. This
* interface implies all the usual responsibilities of a Store implementation,
* and in addition
* <ol>
* <li>The implementation MUST throw an ObsoleteVersionException if the user
* attempts to put a version which is strictly before an existing version
* (concurrent is okay)</li>
* <li>The implementation MUST increment this version number when the value is
* stored.</li>
* <li>The implementation MUST contain an ID identifying it as part of the
* cluster</li>
* </ol>
*
* A hash value can be produced for known subtrees of a StorageEngine
*
*
* @param <K> The type of the key being stored
* @param <V> The type of the value being stored
* @param <T> The type of the transforms
*
*/
public interface StorageEngine<K, V, T> extends Store<K, V, T> {
/**
* Get an iterator over pairs of entries in the store. The key is the first
* element in the pair and the versioned value is the second element.
*
* Note that the iterator need not be threadsafe, and that it must be
* manually closed after use.
*
* @return An iterator over the entries in this StorageEngine.
*/
public ClosableIterator<Pair<K, Versioned<V>>> entries();
/**
* Get an iterator over keys in the store.
*
* Note that the iterator need not be threadsafe, and that it must be
* manually closed after use.
*
* @return An iterator over the keys in this StorageEngine.
*/
public ClosableIterator<K> keys();
/**
* Get an iterator over pairs of entries in a store's partition. The key is
* the first element in the pair and the versioned value is the second
* element.
*
* Note that the iterator need not be threadsafe, and that it must be
* manually closed after use.
*
* @param partition partition whose entries are to be fetched
* @return An iterator over the entries in this StorageEngine.
*/
public ClosableIterator<Pair<K, Versioned<V>>> entries(int partition);
/**
* Get an iterator over keys in the store's partition
*
* Note that the iterator need not be threadsafe, and that it must be
* manually closed after use.
*
* @param partition partition whose keys are to be fetched
* @return An iterator over the keys in this StorageEngine.
*/
public ClosableIterator<K> keys(int partition);
/**
* Truncate all entries in the store
*/
public void truncate();
/**
* Are partitions persisted in distinct files? In other words is the data
* stored on disk on a per-partition basis? This is really for the read-only
* use case in which each partition is stored in a distinct file.
*
* @return Boolean indicating if partitions are persisted in distinct files
* (read-only use case).
*/
public boolean isPartitionAware();
/**
* Does the storage engine support efficient scanning of a single partition?
*
* @return true if the storage engine implements the capability. false
* otherwise
*/
public boolean isPartitionScanSupported();
/**
* A lot of storage engines support efficient methods for performing large
* number of writes (puts/deletes) against the data source. This method puts
* the storage engine in this batch write mode
*
* @return true if the storage engine took successful action to switch to
* 'batch-write' mode
*/
public boolean beginBatchModifications();
/**
* Atomically update storage with the list of versioned values for the given
* key, to improve storage efficiency.
*
* @param key Key to write
* @param values List of versioned values to be written atomically.
* @return list of obsolete versions that were rejected
*/
public List<Versioned<V>> multiVersionPut(K key, List<Versioned<V>> values);
/**
*
* @return true if the storage engine successfully returned to normal mode
*/
public boolean endBatchModifications();
}