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 | |
| 13 | public IKVTable getTable(final String tableName); |
| 14 | |
| 15 | /** |
| 16 | * Drop table. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 17 | * <p/> |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 18 | * 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 61 | * @param version expected version in the data store |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 62 | * @return version after update |
| 63 | * @throws ObjectDoesntExistException |
| 64 | * @throws WrongVersionException |
| 65 | */ |
| 66 | public long update(IKVTableID tableId, byte[] key, byte[] value, long version) |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 67 | throws ObjectDoesntExistException, WrongVersionException; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Update an existing Key-Value entry in table, without checking version. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 71 | * <p/> |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 72 | * FIXME remove this method and use forceCreate for this purpose? |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 73 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 74 | * @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 HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 82 | throws ObjectDoesntExistException; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 83 | |
| 84 | // TODO Adding serialized value as parameter to this interface may |
| 85 | // give an option to improve performance on some backends. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 86 | |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 87 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 88 | * Remove an existing Key-Value entry in table. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 89 | * |
| 90 | * @param tableId |
| 91 | * @param key |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 92 | * @param version expected version in the data store |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 93 | * @return version of removed object |
| 94 | * @throws ObjectDoesntExistException |
| 95 | * @throws WrongVersionException |
| 96 | */ |
| 97 | public long delete(IKVTableID tableId, byte[] key, long version) |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 98 | throws ObjectDoesntExistException, WrongVersionException; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 101 | * Remove a Key-Value entry in table. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 102 | * |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 111 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 112 | * @param tableId |
| 113 | * @return entries in this table. |
| 114 | */ |
| 115 | public Iterable<IKVEntry> getAllEntries(IKVTableID tableId); |
| 116 | |
| 117 | /** |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 118 | * @return IMultiOpEntry for this operation |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 119 | * @see #create(IKVTableID, byte[], byte[]) |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 120 | */ |
| 121 | public IMultiEntryOperation createOp(IKVTableID tableId, byte[] key, byte[] value); |
| 122 | |
| 123 | public IMultiEntryOperation forceCreateOp(IKVTableID tableId, byte[] key, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 124 | byte[] value); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 125 | |
| 126 | public IMultiEntryOperation readOp(IKVTableID tableId, byte[] key); |
| 127 | |
| 128 | public IMultiEntryOperation updateOp(IKVTableID tableId, byte[] key, byte[] value, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 129 | long version); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 130 | |
| 131 | public IMultiEntryOperation deleteOp(IKVTableID tableId, byte[] key, byte[] value, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 132 | long version); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 133 | |
| 134 | public IMultiEntryOperation forceDeleteOp(IKVTableID tableId, byte[] key); |
| 135 | |
| 136 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 137 | * Batch delete operation. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 138 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 139 | * @param ops delete operations |
| 140 | * @return true if failed operation exists |
| 141 | */ |
| 142 | public boolean multiDelete(final Collection<IMultiEntryOperation> ops); |
| 143 | |
| 144 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 145 | * Batch write operation. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 146 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 147 | * @param ops write operations |
| 148 | * @return true if failed operation exists |
| 149 | */ |
| 150 | public boolean multiWrite(final List<IMultiEntryOperation> ops); |
| 151 | |
| 152 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 153 | * Batch read operation. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 154 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 155 | * @param ops read operations |
| 156 | * @return true if failed operation exists |
| 157 | */ |
| 158 | public boolean multiRead(final Collection<IMultiEntryOperation> ops); |
| 159 | |
| 160 | /** |
Yuta HIGUCHI | d47eac3 | 2014-04-07 13:44:47 -0700 | [diff] [blame] | 161 | * 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 HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 211 | * Version number which represents that the object does not exist, or has |
| 212 | * never been read the DB before. |
| 213 | */ |
Ray Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 214 | public long getVersionNonexistant(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 215 | |
| 216 | } |