blob: d3129bce2cd41ba25ab482cf6726e579b9db9616 [file] [log] [blame]
Jonathan Hart6df90172014-04-03 10:13:11 -07001package net.onrc.onos.core.datastore;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -07002
3import java.util.Collection;
4import java.util.List;
5
Jonathan Hart6df90172014-04-03 10:13:11 -07006import net.onrc.onos.core.datastore.IKVTable.IKVEntry;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -07007
8/**
Ray Milkeyb41100a2014-04-10 10:42:15 -07009 * Interface for a client class used to access the Key-Value store.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070010 */
11public interface IKVClient {
12
Yuta HIGUCHI7e5bfbe2014-08-02 16:37:02 -070013 /**
14 * Gets a table for name {@code tableName}.
15 *
16 * Table will be created, if it does not exist.
17 *
18 * @param tableName name of the table
19 * @return {@link IKVTable} for {@code tableName}
20 */
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070021 public IKVTable getTable(final String tableName);
22
23 /**
24 * Drop table.
Ray Milkey269ffb92014-04-03 14:43:30 -070025 * <p/>
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070026 * Behavior of IKVTable instances accessing dropped table is undefined.
27 *
28 * @param table IKVTable to drop.
29 */
30 public void dropTable(IKVTable table);
31
32 /**
33 * Create a Key-Value entry on table.
34 *
35 * @param tableId
36 * @param key
37 * @param value
38 * @return version of the created entry
39 * @throws ObjectExistsException
40 */
41 public long create(IKVTableID tableId, byte[] key, byte[] value) throws ObjectExistsException;
42
43 /**
44 * Create a Key-Value entry on table, without existence checking.
45 *
46 * @param tableId
47 * @param key
48 * @param value
49 * @return version of the created entry
50 */
51 public long forceCreate(IKVTableID tableId, byte[] key, byte[] value);
52
53 /**
54 * Read a Key-Value entry from table.
55 *
56 * @param tableId
57 * @param key
58 * @return Corresponding {@link IKVEntry}
59 * @throws ObjectDoesntExistException
60 */
61 public IKVEntry read(IKVTableID tableId, byte[] key) throws ObjectDoesntExistException;
62
63 /**
64 * Update an existing Key-Value entry in table.
65 *
66 * @param tableId
67 * @param key
68 * @param value
Ray Milkey269ffb92014-04-03 14:43:30 -070069 * @param version expected version in the data store
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070070 * @return version after update
71 * @throws ObjectDoesntExistException
72 * @throws WrongVersionException
73 */
74 public long update(IKVTableID tableId, byte[] key, byte[] value, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070075 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070076
77 /**
78 * Update an existing Key-Value entry in table, without checking version.
Ray Milkey269ffb92014-04-03 14:43:30 -070079 * <p/>
Ray Milkey269ffb92014-04-03 14:43:30 -070080 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070081 * @param tableId
82 * @param key
83 * @param value
84 * @return version after update
85 * @throws ObjectDoesntExistException
86 */
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070087 public long update(IKVTableID tableId, byte[] key, byte[] value)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070088 throws ObjectDoesntExistException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070089
90 // TODO Adding serialized value as parameter to this interface may
91 // give an option to improve performance on some backends.
Ray Milkey269ffb92014-04-03 14:43:30 -070092
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070093 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070094 * Remove an existing Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070095 *
96 * @param tableId
97 * @param key
Ray Milkey269ffb92014-04-03 14:43:30 -070098 * @param version expected version in the data store
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070099 * @return version of removed object
100 * @throws ObjectDoesntExistException
101 * @throws WrongVersionException
102 */
103 public long delete(IKVTableID tableId, byte[] key, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -0700104 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700105
106 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700107 * Remove a Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700108 *
109 * @param tableId
110 * @param key
111 * @return version of removed object or -1, if it did not exist.
112 */
113 public long forceDelete(IKVTableID tableId, byte[] key);
114
115 /**
116 * Get all the entries in table.
Ray Milkey269ffb92014-04-03 14:43:30 -0700117 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700118 * @param tableId
119 * @return entries in this table.
120 */
121 public Iterable<IKVEntry> getAllEntries(IKVTableID tableId);
122
123 /**
Yuta HIGUCHI7e5bfbe2014-08-02 16:37:02 -0700124 * Creates a {@code IMultiEntryOperation}.
125 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700126 * @return IMultiOpEntry for this operation
Ray Milkey269ffb92014-04-03 14:43:30 -0700127 * @see #create(IKVTableID, byte[], byte[])
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700128 */
129 public IMultiEntryOperation createOp(IKVTableID tableId, byte[] key, byte[] value);
130
Yuta HIGUCHI7e5bfbe2014-08-02 16:37:02 -0700131 /**
132 * Creates a {@code IMultiEntryOperation}.
133 *
134 * @return IMultiOpEntry for this operation
135 * @see #forceCreate(IKVTableID, byte[], byte[])
136 */
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700137 public IMultiEntryOperation forceCreateOp(IKVTableID tableId, byte[] key,
Ray Milkey269ffb92014-04-03 14:43:30 -0700138 byte[] value);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700139
Yuta HIGUCHI7e5bfbe2014-08-02 16:37:02 -0700140 /**
141 * Creates a {@code IMultiEntryOperation}.
142 *
143 * @return IMultiOpEntry for this operation
144 * @see #read(IKVTableID, byte[])
145 */
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700146 public IMultiEntryOperation readOp(IKVTableID tableId, byte[] key);
147
Yuta HIGUCHI7e5bfbe2014-08-02 16:37:02 -0700148 /**
149 * Creates a {@code IMultiEntryOperation}.
150 *
151 * @return IMultiOpEntry for this operation
152 * @see #update(IKVTableID, byte[], byte[], long)
153 */
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700154 public IMultiEntryOperation updateOp(IKVTableID tableId, byte[] key, byte[] value,
Ray Milkey269ffb92014-04-03 14:43:30 -0700155 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700156
Yuta HIGUCHI7e5bfbe2014-08-02 16:37:02 -0700157 /**
158 * Creates a {@code IMultiEntryOperation}.
159 *
160 * @return IMultiOpEntry for this operation
161 * @see #delete(IKVTableID, byte[], long)
162 */
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700163 public IMultiEntryOperation deleteOp(IKVTableID tableId, byte[] key, byte[] value,
Ray Milkey269ffb92014-04-03 14:43:30 -0700164 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700165
Yuta HIGUCHI7e5bfbe2014-08-02 16:37:02 -0700166 /**
167 * Creates a {@code IMultiEntryOperation}.
168 *
169 * @return IMultiOpEntry for this operation
170 * @see #forceDelete(IKVTableID, byte[])
171 */
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700172 public IMultiEntryOperation forceDeleteOp(IKVTableID tableId, byte[] key);
173
174 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700175 * Batch delete operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700176 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700177 * @param ops delete operations
178 * @return true if failed operation exists
179 */
180 public boolean multiDelete(final Collection<IMultiEntryOperation> ops);
181
182 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700183 * Batch write operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700184 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700185 * @param ops write operations
186 * @return true if failed operation exists
187 */
188 public boolean multiWrite(final List<IMultiEntryOperation> ops);
189
190 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700191 * Batch read operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700192 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700193 * @param ops read operations
194 * @return true if failed operation exists
195 */
196 public boolean multiRead(final Collection<IMultiEntryOperation> ops);
197
198 /**
Yuta HIGUCHId47eac32014-04-07 13:44:47 -0700199 * Create atomic 64bit integer counter in data store.
200 *
201 * @param tableId
202 * @param key
203 * @param initialValue
204 * @throws ObjectExistsException
205 */
Jonathan Hartc00f5c22014-06-10 15:14:40 -0700206 public void createCounter(final IKVTableID tableId, final byte[] key,
207 final long initialValue) throws ObjectExistsException;
Yuta HIGUCHId47eac32014-04-07 13:44:47 -0700208
209 /**
210 * Set atomic 64bit integer counter in data store to specified value.
211 *
212 * @param tableId
213 * @param key
214 * @param value
215 * @throws ObjectExistsException
216 */
217 public void setCounter(final IKVTableID tableId, final byte[] key, final long value);
218
219 /**
220 * Atomically increment 64bit integer counter in data store.
221 *
222 * @param tableId
223 * @param key key where 64bit integer is stored
224 * @param incrementValue
225 * @return value after incrementing
226 */
227 public long incrementCounter(final IKVTableID tableId, final byte[] key, final long incrementValue);
228
229
230 /**
231 * Get atomic 64bit integer counter value in data store.
232 *
233 * @param tableId
234 * @param key
235 * @return current value
236 * @throws ObjectDoesntExistException
237 */
238 public long getCounter(final IKVTableID tableId, final byte[] key)
239 throws ObjectDoesntExistException;
240
241 /**
242 * Destroy atomic 64bit integer counter in data store.
243 *
244 * @param tableId
245 * @param key
246 */
247 public void destroyCounter(final IKVTableID tableId, final byte[] key);
248
249 /**
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700250 * Version number which represents that the object does not exist, or has
251 * never been read the DB before.
Yuta HIGUCHI7e5bfbe2014-08-02 16:37:02 -0700252 *
253 * @return Version number which represents that the object does not exist
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700254 */
Ray Milkey7531a342014-04-11 15:08:12 -0700255 public long getVersionNonexistant();
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700256
257}