Storage in NoSQL
1
How is data stored in files?
2
In traditional databases: In-place storage
3
1234, John Smith
3434, Mary Bla
…
Sailors Table file
1234, John Smith
2344, Peter Che
3434, Mary Bla
…
Sailors Table file
INSERT INTO Sailors VALUES(2344, Peter Che)
Expensive: random disk access for each INSERT (or UPDATE or DELETE)
NoSQL Storage (e.g., in Cassandra):�Log Structured Merge (LSM) Tree
4
1234, John Smith
4445, Jay Bla
…
Sailors SSTable (file1)
1234, John Smit
3434, Mary Fu
…
Sailors SSTable (file2)
…
4353, May Wilson
9879, Ray Smith
2344, Peter Che
INSERT INTO Sailors VALUES(2344, Peter Che)
RAM
HDD/SSD
MemTable
Periodically Merged (Compacted)
1234, John Smith
434, Mary Fu
4445, Jay Bla
…
LSM Storage
5
LevelDB
6
Sanjay Ghemawat
Jeffrey Dean
LevelDB Compaction
7
Compaction Strategy in Cassandra
8
Compaction Trade-off
9
Bloom Filter: Approximate set membership problem
S = {s1,s2,...,sm} ⊆ universe U
10
Bloom filters
h1,…,hk : U --> {0,1,..,n-1}
1. Initially set the array to 0
2. ∀ s∈S, A[hi(s)] = 1 for 1≤ i ≤ k
(an entry can be set to 1 multiple times, only the first times has an effect )
3. To check if x∈S , we check whether all location A[hi(x)] for 1≤ i ≤ k are set to 1
If not, clearly x∉S.
If all A[hi(x)] are set to 1 ,we assume x∈S
11
[Michael Mitzenmacher Eli Upfal]
12
0
0
0
0
0
0
0
0
0
0
0
0
Initial with all 0
1
1
1
1
1
x1
x2
Each element of S is hashed k times
Each hash location set to 1
1
1
1
1
1
y
To check if y is in S, check the k hash
location. If a 0 appears , y is not in S
1
1
1
1
1
y
If only 1s appear, conclude that y is in S
This may yield false positive
Bloom filters: example
Bloom Filters
13
Conclusion
14