Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 1 | package org.onlab.onos.store.service; |
| 2 | |
Madan Jampani | 37c2e70 | 2014-11-04 18:11:10 -0800 | [diff] [blame] | 3 | /** |
| 4 | * Service interface for a strongly consistent and durable |
| 5 | * key value data store. |
| 6 | */ |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 7 | public interface DatabaseService { |
| 8 | |
| 9 | /** |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 10 | * Reads the specified key. |
| 11 | * @param tableName name of the table associated with this operation. |
Thomas Vachuska | 2292567 | 2014-11-11 17:57:53 -0800 | [diff] [blame] | 12 | * @param key key to read. |
| 13 | * @return value (and version) associated with this key. This calls returns null if the key does not exist. |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 14 | */ |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 15 | VersionedValue get(String tableName, String key); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 16 | |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 17 | /** |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 18 | * Associate the key with a value. |
| 19 | * @param tableName table name in which this key/value resides. |
| 20 | * @param key key with which the specified value is to be associated |
| 21 | * @param value value to be associated with the specified key |
| 22 | * @return the previous value associated with the specified key, or null if there was no mapping for the key. |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 23 | */ |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 24 | VersionedValue put(String tableName, String key, byte[] value); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 25 | |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 26 | /** |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 27 | * If the specified key is not already associated with a value, associate it with the given value. |
| 28 | * @param tableName table name in which this key/value resides. |
| 29 | * @param key key with which the specified value is to be associated |
| 30 | * @param value value to be associated with the specified key |
| 31 | * @return true if put was successful, false if there is already a value associated with this key |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 32 | */ |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 33 | boolean putIfAbsent(String tableName, String key, byte[] value); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 34 | |
Yuta HIGUCHI | 361664e | 2014-11-06 17:28:47 -0800 | [diff] [blame] | 35 | /** |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 36 | * Sets the key to the specified value if the version in the database (for that key) |
| 37 | * matches the specified version. |
| 38 | * @param tableName name of table associated with this operation. |
| 39 | * @param key key |
| 40 | * @param value value |
| 41 | * @param version version that should present in the database for the put to be successful. |
| 42 | * @return true if put was successful, false if there version in database is different from what is specified. |
Yuta HIGUCHI | 361664e | 2014-11-06 17:28:47 -0800 | [diff] [blame] | 43 | */ |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 44 | boolean putIfVersionMatches(String tableName, String key, byte[] value, long version); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 45 | |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 46 | /** |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 47 | * Replaces the entry for a key only if currently mapped to a given value. |
| 48 | * @param tableName name of table associated with this operation. |
| 49 | * @param key with which the specified value is associated |
| 50 | * @param oldValue value expected to be associated with the specified key |
| 51 | * @param newValue value to be associated with the specified key |
| 52 | * @return true if put was successful, false if there version in database is different from what is specified. |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 53 | */ |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 54 | boolean putIfValueMatches(String tableName, String key, byte[] oldValue, byte[] newValue); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 55 | |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 56 | /** |
| 57 | * Removes the key (and associated value). |
| 58 | * @param tableName name of table associated with this operation. |
| 59 | * @param key key to remove |
| 60 | * @return value previously associated with the key. This call returns null if the key does not exist. |
| 61 | */ |
| 62 | VersionedValue remove(String tableName, String key); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 63 | |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 64 | /** |
| 65 | * Removes the key (and associated value) if the version in the database matches specified version. |
| 66 | * @param tableName name of table associated with this operation. |
| 67 | * @param key key to remove |
| 68 | * @param version version that should present in the database for the remove to be successful. |
| 69 | * @return true if remove was successful, false if there version in database is different from what is specified. |
| 70 | */ |
| 71 | boolean removeIfVersionMatches(String tableName, String key, long version); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 72 | |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 73 | /** |
| 74 | * Removes the key (and associated value) if the value in the database matches specified value. |
| 75 | * @param tableName name of table associated with this operation. |
| 76 | * @param key key to remove |
| 77 | * @param value value that should present in the database for the remove to be successful. |
| 78 | * @return true if remove was successful, false if there value in database is different from what is specified. |
| 79 | */ |
| 80 | boolean removeIfValueMatches(String tableName, String key, byte[] value); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 81 | |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 82 | /** |
| 83 | * Performs a batch read operation and returns the results. |
| 84 | * @param batchRequest batch request. |
| 85 | * @return result of the batch operation. |
| 86 | */ |
| 87 | BatchReadResult batchRead(BatchReadRequest batchRequest); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 88 | |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 89 | /** |
| 90 | * Performs a batch write operation and returns the results. |
| 91 | * This method provides transactional semantics. Either all writes succeed or none do. |
| 92 | * Even a single write failure would cause the entire batch to be aborted. |
| 93 | * In the case of unsuccessful operation, the batch result can be inspected to determine |
| 94 | * which operation(s) caused the batch to fail. |
| 95 | * @param batchRequest batch request. |
| 96 | * @return result of the batch operation. |
| 97 | */ |
| 98 | BatchWriteResult batchWrite(BatchWriteRequest batchRequest); |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 99 | } |