Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
dgraph
Commits
1ce8732d
Commit
1ce8732d
authored
9 years ago
by
Ashwin
Browse files
Options
Downloads
Patches
Plain Diff
Detect duplicate keys using rocksDB store itself
parent
b37e6c1b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/merge/.gitignore
+1
-0
1 addition, 0 deletions
tools/merge/.gitignore
tools/merge/merge.cc
+23
-12
23 additions, 12 deletions
tools/merge/merge.cc
with
24 additions
and
12 deletions
tools/merge/.gitignore
+
1
−
0
View file @
1ce8732d
/a.out
/merge
This diff is collapsed.
Click to expand it.
tools/merge/merge.cc
+
23
−
12
View file @
1ce8732d
/*
* Author : Ashwin <ashwin2007ray@gmail.com>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* compile : g++ rocks_merge.cc <path_to_rocksDB_installation>/librocksdb.so.4.1 --std=c++11 -lstdc++fs
* usage : ./<executable> <folder_having_rocksDB_directories_to_be_merged> <destination_folder>
...
...
@@ -10,7 +20,6 @@
#include
<cstdio>
#include
<iostream>
#include
<string>
#include
<unordered_map>
#include
"rocksdb/db.h"
#include
"rocksdb/options.h"
...
...
@@ -22,12 +31,12 @@ namespace fs = std::experimental::filesystem;
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
3
)
{
std
::
cerr
<<
"Wrong number of arguments
\n
usage : ./<executable> <folder_having_rocksDB_directories_to_be_merged> <destination_folder>
\n
"
;
std
::
cerr
<<
"Wrong number of arguments
\n
usage : ./<executable>\
<folder_having_rocksDB_directories_to_be_merged> <destination_folder>
\n
"
;
exit
(
0
);
}
std
::
unordered_map
<
std
::
string
,
std
::
string
>
xid_uid_mp
;
std
::
string
destinationDB
=
argv
[
2
];
std
::
string
destinationDB
=
argv
[
2
],
mergeDir
=
argv
[
1
];
DB
*
db
;
Options
options
;
// Optimize RocksDB. This is the easiest way to get RocksDB to perform well
...
...
@@ -40,8 +49,8 @@ int main(int argc, char* argv[]) {
Status
s
=
DB
::
Open
(
options
,
destinationDB
,
&
db
);
assert
(
s
.
ok
());
for
(
auto
&
dirEntry
:
fs
::
directory_iterator
(
argv
[
1
]
))
{
std
::
cout
<<
dirEntry
<<
"
\n
"
;
for
(
auto
&
dirEntry
:
fs
::
directory_iterator
(
mergeDir
))
{
std
::
cout
<<
dirEntry
<<
std
::
endl
;
DB
*
cur_db
;
Options
options
;
options
.
IncreaseParallelism
();
...
...
@@ -55,12 +64,14 @@ int main(int argc, char* argv[]) {
rocksdb
::
Iterator
*
it
=
cur_db
->
NewIterator
(
rocksdb
::
ReadOptions
());
for
(
it
->
SeekToFirst
();
it
->
Valid
();
it
->
Next
())
{
if
(
xid_uid_mp
.
count
(
it
->
key
().
ToString
())
!=
0
&&
xid_uid_mp
[
it
->
key
().
ToString
()]
!=
it
->
value
().
ToString
())
{
std
::
cerr
<<
"FATAL : Different value for same key : "
<<
it
->
key
().
ToString
()
<<
std
::
endl
;
exit
(
0
);
std
::
string
key_s
=
it
->
key
().
ToString
();
std
::
string
val_s
=
it
->
value
().
ToString
();
std
::
string
val_t
;
Status
s
=
db
->
Get
(
ReadOptions
(),
key_s
,
&
val_t
);
if
(
s
.
ok
())
{
assert
(
val_t
==
val_s
&&
"Same key has different value"
);
}
else
{
xid_uid_mp
[
it
->
key
().
ToString
()]
=
it
->
value
().
ToString
();
s
=
db
->
Put
(
WriteOptions
(),
it
->
key
().
ToString
(),
it
->
value
().
ToString
());
s
=
db
->
Put
(
WriteOptions
(),
key_s
,
val_s
);
assert
(
s
.
ok
());
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment