blob: 57d81f27867b00d05af37089ac03c5dddc0d6625 [file] [log] [blame]
Madan Jampani08822c42014-11-04 17:17:46 -08001package org.onlab.onos.store.service;
2
Madan Jampani37c2e702014-11-04 18:11:10 -08003/**
4 * Service interface for a strongly consistent and durable
5 * key value data store.
6 */
Madan Jampani08822c42014-11-04 17:17:46 -08007public interface DatabaseService {
8
9 /**
Madan Jampani12390c12014-11-12 00:35:56 -080010 * Reads the specified key.
11 * @param tableName name of the table associated with this operation.
12 * @return key key to read.
13 * @returns value (and version) associated with this key. This calls returns null if the key does not exist.
Madan Jampani08822c42014-11-04 17:17:46 -080014 */
Madan Jampani12390c12014-11-12 00:35:56 -080015 VersionedValue get(String tableName, String key);
16
Madan Jampani08822c42014-11-04 17:17:46 -080017 /**
Madan Jampani12390c12014-11-12 00:35:56 -080018 * 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 Jampani08822c42014-11-04 17:17:46 -080023 */
Madan Jampani12390c12014-11-12 00:35:56 -080024 VersionedValue put(String tableName, String key, byte[] value);
25
Madan Jampani08822c42014-11-04 17:17:46 -080026 /**
Madan Jampani12390c12014-11-12 00:35:56 -080027 * 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 Jampani08822c42014-11-04 17:17:46 -080032 */
Madan Jampani12390c12014-11-12 00:35:56 -080033 boolean putIfAbsent(String tableName, String key, byte[] value);
34
Yuta HIGUCHI361664e2014-11-06 17:28:47 -080035 /**
Madan Jampani12390c12014-11-12 00:35:56 -080036 * 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 HIGUCHI361664e2014-11-06 17:28:47 -080043 */
Madan Jampani12390c12014-11-12 00:35:56 -080044 boolean putIfVersionMatches(String tableName, String key, byte[] value, long version);
45
Madan Jampani08822c42014-11-04 17:17:46 -080046 /**
Madan Jampani12390c12014-11-12 00:35:56 -080047 * 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 Jampani08822c42014-11-04 17:17:46 -080053 */
Madan Jampani12390c12014-11-12 00:35:56 -080054 boolean putIfValueMatches(String tableName, String key, byte[] oldValue, byte[] newValue);
55
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);
63
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);
72
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);
81
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);
88
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);
99}