blob: a59a8a96981c18d50215aa909c279edc2e4d2842 [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
13 public IKVTable getTable(final String tableName);
14
15 /**
16 * Drop table.
Ray Milkey269ffb92014-04-03 14:43:30 -070017 * <p/>
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070018 * Behavior of IKVTable instances accessing dropped table is undefined.
19 *
20 * @param table IKVTable to drop.
21 */
22 public void dropTable(IKVTable table);
23
24 /**
25 * Create a Key-Value entry on table.
26 *
27 * @param tableId
28 * @param key
29 * @param value
30 * @return version of the created entry
31 * @throws ObjectExistsException
32 */
33 public long create(IKVTableID tableId, byte[] key, byte[] value) throws ObjectExistsException;
34
35 /**
36 * Create a Key-Value entry on table, without existence checking.
37 *
38 * @param tableId
39 * @param key
40 * @param value
41 * @return version of the created entry
42 */
43 public long forceCreate(IKVTableID tableId, byte[] key, byte[] value);
44
45 /**
46 * Read a Key-Value entry from table.
47 *
48 * @param tableId
49 * @param key
50 * @return Corresponding {@link IKVEntry}
51 * @throws ObjectDoesntExistException
52 */
53 public IKVEntry read(IKVTableID tableId, byte[] key) throws ObjectDoesntExistException;
54
55 /**
56 * Update an existing Key-Value entry in table.
57 *
58 * @param tableId
59 * @param key
60 * @param value
Ray Milkey269ffb92014-04-03 14:43:30 -070061 * @param version expected version in the data store
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070062 * @return version after update
63 * @throws ObjectDoesntExistException
64 * @throws WrongVersionException
65 */
66 public long update(IKVTableID tableId, byte[] key, byte[] value, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070067 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070068
69 /**
70 * Update an existing Key-Value entry in table, without checking version.
Ray Milkey269ffb92014-04-03 14:43:30 -070071 * <p/>
Ray Milkey269ffb92014-04-03 14:43:30 -070072 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070073 * @param tableId
74 * @param key
75 * @param value
76 * @return version after update
77 * @throws ObjectDoesntExistException
78 */
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070079 public long update(IKVTableID tableId, byte[] key, byte[] value)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070080 throws ObjectDoesntExistException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070081
82 // TODO Adding serialized value as parameter to this interface may
83 // give an option to improve performance on some backends.
Ray Milkey269ffb92014-04-03 14:43:30 -070084
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070085 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070086 * Remove an existing Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070087 *
88 * @param tableId
89 * @param key
Ray Milkey269ffb92014-04-03 14:43:30 -070090 * @param version expected version in the data store
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070091 * @return version of removed object
92 * @throws ObjectDoesntExistException
93 * @throws WrongVersionException
94 */
95 public long delete(IKVTableID tableId, byte[] key, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070096 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070097
98 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070099 * Remove a Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700100 *
101 * @param tableId
102 * @param key
103 * @return version of removed object or -1, if it did not exist.
104 */
105 public long forceDelete(IKVTableID tableId, byte[] key);
106
107 /**
108 * Get all the entries in table.
Ray Milkey269ffb92014-04-03 14:43:30 -0700109 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700110 * @param tableId
111 * @return entries in this table.
112 */
113 public Iterable<IKVEntry> getAllEntries(IKVTableID tableId);
114
115 /**
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700116 * @return IMultiOpEntry for this operation
Ray Milkey269ffb92014-04-03 14:43:30 -0700117 * @see #create(IKVTableID, byte[], byte[])
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700118 */
119 public IMultiEntryOperation createOp(IKVTableID tableId, byte[] key, byte[] value);
120
121 public IMultiEntryOperation forceCreateOp(IKVTableID tableId, byte[] key,
Ray Milkey269ffb92014-04-03 14:43:30 -0700122 byte[] value);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700123
124 public IMultiEntryOperation readOp(IKVTableID tableId, byte[] key);
125
126 public IMultiEntryOperation updateOp(IKVTableID tableId, byte[] key, byte[] value,
Ray Milkey269ffb92014-04-03 14:43:30 -0700127 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700128
129 public IMultiEntryOperation deleteOp(IKVTableID tableId, byte[] key, byte[] value,
Ray Milkey269ffb92014-04-03 14:43:30 -0700130 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700131
132 public IMultiEntryOperation forceDeleteOp(IKVTableID tableId, byte[] key);
133
134 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700135 * Batch delete operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700136 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700137 * @param ops delete operations
138 * @return true if failed operation exists
139 */
140 public boolean multiDelete(final Collection<IMultiEntryOperation> ops);
141
142 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700143 * Batch write operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700144 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700145 * @param ops write operations
146 * @return true if failed operation exists
147 */
148 public boolean multiWrite(final List<IMultiEntryOperation> ops);
149
150 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700151 * Batch read operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700152 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700153 * @param ops read operations
154 * @return true if failed operation exists
155 */
156 public boolean multiRead(final Collection<IMultiEntryOperation> ops);
157
158 /**
Yuta HIGUCHId47eac32014-04-07 13:44:47 -0700159 * Create atomic 64bit integer counter in data store.
160 *
161 * @param tableId
162 * @param key
163 * @param initialValue
164 * @throws ObjectExistsException
165 */
166 public void createCounter(final IKVTableID tableId, final byte[] key, final long initialValue) throws ObjectExistsException;
167
168 /**
169 * Set atomic 64bit integer counter in data store to specified value.
170 *
171 * @param tableId
172 * @param key
173 * @param value
174 * @throws ObjectExistsException
175 */
176 public void setCounter(final IKVTableID tableId, final byte[] key, final long value);
177
178 /**
179 * Atomically increment 64bit integer counter in data store.
180 *
181 * @param tableId
182 * @param key key where 64bit integer is stored
183 * @param incrementValue
184 * @return value after incrementing
185 */
186 public long incrementCounter(final IKVTableID tableId, final byte[] key, final long incrementValue);
187
188
189 /**
190 * Get atomic 64bit integer counter value in data store.
191 *
192 * @param tableId
193 * @param key
194 * @return current value
195 * @throws ObjectDoesntExistException
196 */
197 public long getCounter(final IKVTableID tableId, final byte[] key)
198 throws ObjectDoesntExistException;
199
200 /**
201 * Destroy atomic 64bit integer counter in data store.
202 *
203 * @param tableId
204 * @param key
205 */
206 public void destroyCounter(final IKVTableID tableId, final byte[] key);
207
208 /**
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700209 * Version number which represents that the object does not exist, or has
210 * never been read the DB before.
211 */
Ray Milkey7531a342014-04-11 15:08:12 -0700212 public long getVersionNonexistant();
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700213
214}