blob: 4736928d608d77548b1d3ad934cbe63ca2268950 [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/>
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070072 * FIXME remove this method and use forceCreate for this purpose?
Ray Milkey269ffb92014-04-03 14:43:30 -070073 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070074 * @param tableId
75 * @param key
76 * @param value
77 * @return version after update
78 * @throws ObjectDoesntExistException
79 */
80 @Deprecated
81 public long update(IKVTableID tableId, byte[] key, byte[] value)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070082 throws ObjectDoesntExistException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070083
84 // TODO Adding serialized value as parameter to this interface may
85 // give an option to improve performance on some backends.
Ray Milkey269ffb92014-04-03 14:43:30 -070086
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070087 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070088 * Remove an existing Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070089 *
90 * @param tableId
91 * @param key
Ray Milkey269ffb92014-04-03 14:43:30 -070092 * @param version expected version in the data store
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070093 * @return version of removed object
94 * @throws ObjectDoesntExistException
95 * @throws WrongVersionException
96 */
97 public long delete(IKVTableID tableId, byte[] key, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070098 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070099
100 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700101 * Remove a Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700102 *
103 * @param tableId
104 * @param key
105 * @return version of removed object or -1, if it did not exist.
106 */
107 public long forceDelete(IKVTableID tableId, byte[] key);
108
109 /**
110 * Get all the entries in table.
Ray Milkey269ffb92014-04-03 14:43:30 -0700111 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700112 * @param tableId
113 * @return entries in this table.
114 */
115 public Iterable<IKVEntry> getAllEntries(IKVTableID tableId);
116
117 /**
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700118 * @return IMultiOpEntry for this operation
Ray Milkey269ffb92014-04-03 14:43:30 -0700119 * @see #create(IKVTableID, byte[], byte[])
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700120 */
121 public IMultiEntryOperation createOp(IKVTableID tableId, byte[] key, byte[] value);
122
123 public IMultiEntryOperation forceCreateOp(IKVTableID tableId, byte[] key,
Ray Milkey269ffb92014-04-03 14:43:30 -0700124 byte[] value);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700125
126 public IMultiEntryOperation readOp(IKVTableID tableId, byte[] key);
127
128 public IMultiEntryOperation updateOp(IKVTableID tableId, byte[] key, byte[] value,
Ray Milkey269ffb92014-04-03 14:43:30 -0700129 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700130
131 public IMultiEntryOperation deleteOp(IKVTableID tableId, byte[] key, byte[] value,
Ray Milkey269ffb92014-04-03 14:43:30 -0700132 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700133
134 public IMultiEntryOperation forceDeleteOp(IKVTableID tableId, byte[] key);
135
136 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700137 * Batch delete operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700138 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700139 * @param ops delete operations
140 * @return true if failed operation exists
141 */
142 public boolean multiDelete(final Collection<IMultiEntryOperation> ops);
143
144 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700145 * Batch write operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700146 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700147 * @param ops write operations
148 * @return true if failed operation exists
149 */
150 public boolean multiWrite(final List<IMultiEntryOperation> ops);
151
152 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700153 * Batch read operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700154 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700155 * @param ops read operations
156 * @return true if failed operation exists
157 */
158 public boolean multiRead(final Collection<IMultiEntryOperation> ops);
159
160 /**
Yuta HIGUCHId47eac32014-04-07 13:44:47 -0700161 * Create atomic 64bit integer counter in data store.
162 *
163 * @param tableId
164 * @param key
165 * @param initialValue
166 * @throws ObjectExistsException
167 */
168 public void createCounter(final IKVTableID tableId, final byte[] key, final long initialValue) throws ObjectExistsException;
169
170 /**
171 * Set atomic 64bit integer counter in data store to specified value.
172 *
173 * @param tableId
174 * @param key
175 * @param value
176 * @throws ObjectExistsException
177 */
178 public void setCounter(final IKVTableID tableId, final byte[] key, final long value);
179
180 /**
181 * Atomically increment 64bit integer counter in data store.
182 *
183 * @param tableId
184 * @param key key where 64bit integer is stored
185 * @param incrementValue
186 * @return value after incrementing
187 */
188 public long incrementCounter(final IKVTableID tableId, final byte[] key, final long incrementValue);
189
190
191 /**
192 * Get atomic 64bit integer counter value in data store.
193 *
194 * @param tableId
195 * @param key
196 * @return current value
197 * @throws ObjectDoesntExistException
198 */
199 public long getCounter(final IKVTableID tableId, final byte[] key)
200 throws ObjectDoesntExistException;
201
202 /**
203 * Destroy atomic 64bit integer counter in data store.
204 *
205 * @param tableId
206 * @param key
207 */
208 public void destroyCounter(final IKVTableID tableId, final byte[] key);
209
210 /**
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700211 * Version number which represents that the object does not exist, or has
212 * never been read the DB before.
213 */
Ray Milkey7531a342014-04-11 15:08:12 -0700214 public long getVersionNonexistant();
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700215
216}