-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This includes a filter by cell timestamp. This also includes a lot of inline comments pointing out potential hazards and pitfalls that I experienced working on this. NOTE: There is a (hopefully remote) possibility that a record could be returned with a specific cell missing if that cell's timestamp has expired. Timestamps are per cell, not per row. Closes: SYNC-4060
- Loading branch information
Showing
4 changed files
with
125 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
autopush-common/src/db/bigtable/bigtable_client/Bigtable_Learnings.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Various things we learned while dealing with Bigtable | ||
|
||
This document contains tricks and traps that we've discovered while working with Bigtable. | ||
|
||
## Indicies | ||
|
||
* Bigtable uses a single key, which it uses to locate data as proximate to other values (e.g. | ||
"Foo-123" would be stored proximate to "Foo-456"). The suggested mechanism is to collapse significant values into a single key using well-known separator values and use regular-expression syntax for the key index to limit searches. | ||
|
||
* Regular expressions must match the entire key. A partial match is not considered for inclusion in the result set. (e.g. `Foo` will not match `Foo-123`, however `Foo.*` will) | ||
|
||
## Cells | ||
|
||
* Cell values are stored as Byte arrays, and library functions use field hints in order to store and retrieve values, but be mindful of storage differences. (e.g. a u64 value or search will not match a u128 byte array.) | ||
|
||
## Filters | ||
|
||
* Cell Filters are exclusive by default. This means that when you do a filter for a given cell value or qualifier, the result set will only contain the filtered results. | ||
This is a bit hard to explain without a proper example, but presume the following filter: | ||
|
||
```rust | ||
fn expiry_filter() -> Result<data::RowFilter, error::BigTableError> { | ||
let mut expiry_filter = data::RowFilter::default(); | ||
let mut chain = data::RowFilter_Chain::default(); | ||
let mut filter_chain = RepeatedField::default(); | ||
|
||
let mut key_filter = data::RowFilter::default(); | ||
key_filter.set_column_qualifier_regex_filter("expiry".as_bytes().to_vec()); | ||
let bt_now: u128 = SystemTime::now() | ||
.duration_since(SystemTime::UNIX_EPOCH) | ||
.map_err(error::BigTableError::WriteTime)? | ||
.as_millis(); | ||
let mut value_filter = data::RowFilter::default(); | ||
let mut range = data::ValueRange::default(); | ||
|
||
// Valid timestamps have not yet expired. | ||
range.set_start_value_open(bt_now.to_be_bytes().to_vec()); | ||
value_filter.set_value_range_filter(range); | ||
filter_chain.push(key_filter); | ||
filter_chain.push(value_filter); | ||
chain.set_filters(filter_chain); | ||
expiry_filter.set_chain(chain); | ||
Ok(expiry_filter) | ||
} | ||
|
||
``` | ||
|
||
Adding this filter to a query will return a result that only includes the "expiry" cells which have a value that is greater than the current time. No other cells or values will be included in the return set, however each "row" will include the row meta information, including the key. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters