Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.datastore; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 2 | |
| 3 | import java.util.Collection; |
| 4 | import java.util.List; |
| 5 | |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 6 | import net.onrc.onos.core.datastore.IKVTable.IKVEntry; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 7 | |
| 8 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 9 | * Interface for a client class used to access the Key-Value store. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 10 | */ |
| 11 | public interface IKVClient { |
| 12 | |
Yuta HIGUCHI | 7e5bfbe | 2014-08-02 16:37:02 -0700 | [diff] [blame] | 13 | /** |
| 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 HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 21 | public IKVTable getTable(final String tableName); |
| 22 | |
| 23 | /** |
| 24 | * Drop table. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | * <p/> |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 26 | * 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 69 | * @param version expected version in the data store |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 70 | * @return version after update |
| 71 | * @throws ObjectDoesntExistException |
| 72 | * @throws WrongVersionException |
| 73 | */ |
| 74 | public long update(IKVTableID tableId, byte[] key, byte[] value, long version) |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 75 | throws ObjectDoesntExistException, WrongVersionException; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * Update an existing Key-Value entry in table, without checking version. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 79 | * <p/> |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 80 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 81 | * @param tableId |
| 82 | * @param key |
| 83 | * @param value |
| 84 | * @return version after update |
| 85 | * @throws ObjectDoesntExistException |
| 86 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 87 | public long update(IKVTableID tableId, byte[] key, byte[] value) |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 88 | throws ObjectDoesntExistException; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 89 | |
| 90 | // TODO Adding serialized value as parameter to this interface may |
| 91 | // give an option to improve performance on some backends. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 92 | |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 93 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 94 | * Remove an existing Key-Value entry in table. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 95 | * |
| 96 | * @param tableId |
| 97 | * @param key |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 98 | * @param version expected version in the data store |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 99 | * @return version of removed object |
| 100 | * @throws ObjectDoesntExistException |
| 101 | * @throws WrongVersionException |
| 102 | */ |
| 103 | public long delete(IKVTableID tableId, byte[] key, long version) |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 104 | throws ObjectDoesntExistException, WrongVersionException; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 107 | * Remove a Key-Value entry in table. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 108 | * |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 117 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 118 | * @param tableId |
| 119 | * @return entries in this table. |
| 120 | */ |
| 121 | public Iterable<IKVEntry> getAllEntries(IKVTableID tableId); |
| 122 | |
| 123 | /** |
Yuta HIGUCHI | 7e5bfbe | 2014-08-02 16:37:02 -0700 | [diff] [blame] | 124 | * Creates a {@code IMultiEntryOperation}. |
| 125 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 126 | * @return IMultiOpEntry for this operation |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 127 | * @see #create(IKVTableID, byte[], byte[]) |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 128 | */ |
| 129 | public IMultiEntryOperation createOp(IKVTableID tableId, byte[] key, byte[] value); |
| 130 | |
Yuta HIGUCHI | 7e5bfbe | 2014-08-02 16:37:02 -0700 | [diff] [blame] | 131 | /** |
| 132 | * Creates a {@code IMultiEntryOperation}. |
| 133 | * |
| 134 | * @return IMultiOpEntry for this operation |
| 135 | * @see #forceCreate(IKVTableID, byte[], byte[]) |
| 136 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 137 | public IMultiEntryOperation forceCreateOp(IKVTableID tableId, byte[] key, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 138 | byte[] value); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 139 | |
Yuta HIGUCHI | 7e5bfbe | 2014-08-02 16:37:02 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Creates a {@code IMultiEntryOperation}. |
| 142 | * |
| 143 | * @return IMultiOpEntry for this operation |
| 144 | * @see #read(IKVTableID, byte[]) |
| 145 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 146 | public IMultiEntryOperation readOp(IKVTableID tableId, byte[] key); |
| 147 | |
Yuta HIGUCHI | 7e5bfbe | 2014-08-02 16:37:02 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Creates a {@code IMultiEntryOperation}. |
| 150 | * |
| 151 | * @return IMultiOpEntry for this operation |
| 152 | * @see #update(IKVTableID, byte[], byte[], long) |
| 153 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 154 | public IMultiEntryOperation updateOp(IKVTableID tableId, byte[] key, byte[] value, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 155 | long version); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 156 | |
Yuta HIGUCHI | 7e5bfbe | 2014-08-02 16:37:02 -0700 | [diff] [blame] | 157 | /** |
| 158 | * Creates a {@code IMultiEntryOperation}. |
| 159 | * |
| 160 | * @return IMultiOpEntry for this operation |
| 161 | * @see #delete(IKVTableID, byte[], long) |
| 162 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 163 | public IMultiEntryOperation deleteOp(IKVTableID tableId, byte[] key, byte[] value, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 164 | long version); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 165 | |
Yuta HIGUCHI | 7e5bfbe | 2014-08-02 16:37:02 -0700 | [diff] [blame] | 166 | /** |
| 167 | * Creates a {@code IMultiEntryOperation}. |
| 168 | * |
| 169 | * @return IMultiOpEntry for this operation |
| 170 | * @see #forceDelete(IKVTableID, byte[]) |
| 171 | */ |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 172 | public IMultiEntryOperation forceDeleteOp(IKVTableID tableId, byte[] key); |
| 173 | |
| 174 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 175 | * Batch delete operation. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 176 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 177 | * @param ops delete operations |
| 178 | * @return true if failed operation exists |
| 179 | */ |
| 180 | public boolean multiDelete(final Collection<IMultiEntryOperation> ops); |
| 181 | |
| 182 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 183 | * Batch write operation. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 184 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 185 | * @param ops write operations |
| 186 | * @return true if failed operation exists |
| 187 | */ |
| 188 | public boolean multiWrite(final List<IMultiEntryOperation> ops); |
| 189 | |
| 190 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 191 | * Batch read operation. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 192 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 193 | * @param ops read operations |
| 194 | * @return true if failed operation exists |
| 195 | */ |
| 196 | public boolean multiRead(final Collection<IMultiEntryOperation> ops); |
| 197 | |
| 198 | /** |
Yuta HIGUCHI | d47eac3 | 2014-04-07 13:44:47 -0700 | [diff] [blame] | 199 | * Create atomic 64bit integer counter in data store. |
| 200 | * |
| 201 | * @param tableId |
| 202 | * @param key |
| 203 | * @param initialValue |
| 204 | * @throws ObjectExistsException |
| 205 | */ |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 206 | public void createCounter(final IKVTableID tableId, final byte[] key, |
| 207 | final long initialValue) throws ObjectExistsException; |
Yuta HIGUCHI | d47eac3 | 2014-04-07 13:44:47 -0700 | [diff] [blame] | 208 | |
| 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 HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 250 | * Version number which represents that the object does not exist, or has |
| 251 | * never been read the DB before. |
Yuta HIGUCHI | 7e5bfbe | 2014-08-02 16:37:02 -0700 | [diff] [blame] | 252 | * |
| 253 | * @return Version number which represents that the object does not exist |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 254 | */ |
Ray Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 255 | public long getVersionNonexistant(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 256 | |
| 257 | } |