Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
eos
QuarkDB
Commits
0079a1c7
Commit
0079a1c7
authored
Aug 10, 2018
by
Georgios Bitzes
Browse files
Use unique_ptr for rocksdb::DB to prevent memory leak if StateMachine throws in constructor
parent
e2d4aabc
Pipeline
#477505
failed with stages
in 30 minutes and 4 seconds
Changes
4
Pipelines
9
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
0079a1c7
...
...
@@ -12,6 +12,9 @@ All notable changes to this project will be documented in this file.
From now on, a node which has been vetoed will abstain from starting election
rounds until it has received fresh heartbeats since receiving that veto.
### Fixed
-
A couple of minor memory leaks.
## 0.3.1 (2018-08-03)
### Added
-
Command
`hclone`
for creating identical copies of entire hashes.
...
...
src/StateMachine.cc
View file @
0079a1c7
...
...
@@ -139,9 +139,11 @@ StateMachine::StateMachine(const std::string &f, bool write_ahead_log, bool bulk
options
.
allow_concurrent_memtable_write
=
false
;
}
rocksdb
::
Status
status
=
rocksdb
::
DB
::
Open
(
options
,
filename
,
&
db
);
rocksdb
::
DB
*
tmpdb
=
nullptr
;
rocksdb
::
Status
status
=
rocksdb
::
DB
::
Open
(
options
,
filename
,
&
tmpdb
);
if
(
!
status
.
ok
())
qdb_throw
(
"Cannot open "
<<
quotes
(
filename
)
<<
":"
<<
status
.
ToString
());
db
.
reset
(
tmpdb
);
ensureCompatibleFormat
(
!
dirExists
);
ensureBulkloadSanity
(
!
dirExists
);
ensureClockSanity
(
!
dirExists
);
...
...
@@ -182,8 +184,7 @@ StateMachine::~StateMachine() {
if
(
db
)
{
qdb_info
(
"Closing state machine "
<<
quotes
(
filename
));
delete
db
;
db
=
nullptr
;
db
.
reset
();
}
}
...
...
@@ -594,7 +595,7 @@ rocksdb::Status StateMachine::lhlen(StagingArea &stagingArea, const std::string
}
rocksdb
::
Status
StateMachine
::
rawGetAllVersions
(
const
std
::
string
&
key
,
std
::
vector
<
rocksdb
::
KeyVersion
>
&
versions
)
{
return
rocksdb
::
GetAllKeyVersions
(
db
,
key
,
key
,
&
versions
);
return
rocksdb
::
GetAllKeyVersions
(
db
.
get
()
,
key
,
key
,
&
versions
);
}
rocksdb
::
Status
StateMachine
::
rawScan
(
StagingArea
&
stagingArea
,
const
std
::
string
&
key
,
size_t
count
,
std
::
vector
<
std
::
string
>
&
elements
)
{
...
...
@@ -1470,7 +1471,7 @@ rocksdb::Status StateMachine::flushall(StagingArea &stagingArea) {
rocksdb
::
Status
StateMachine
::
checkpoint
(
const
std
::
string
&
path
)
{
rocksdb
::
Checkpoint
*
checkpoint
=
nullptr
;
RETURN_ON_ERROR
(
rocksdb
::
Checkpoint
::
Create
(
db
,
&
checkpoint
));
RETURN_ON_ERROR
(
rocksdb
::
Checkpoint
::
Create
(
db
.
get
()
,
&
checkpoint
));
rocksdb
::
Status
st
=
checkpoint
->
CreateCheckpoint
(
path
);
delete
checkpoint
;
...
...
src/StateMachine.hh
View file @
0079a1c7
...
...
@@ -295,7 +295,7 @@ private:
std
::
mutex
lastAppliedMtx
;
std
::
mutex
writeMtx
;
rocksdb
::
DB
*
db
=
nullptr
;
std
::
unique_ptr
<
rocksdb
::
DB
>
db
;
std
::
unique_ptr
<
ConsistencyScanner
>
consistencyScanner
;
...
...
src/storage/StagingArea.hh
View file @
0079a1c7
...
...
@@ -49,7 +49,7 @@ public:
if
(
readOnly
)
{
// Acquire snapshot.
snapshot
.
reset
(
new
StateMachine
::
Snapshot
(
sm
.
db
));
snapshot
.
reset
(
new
StateMachine
::
Snapshot
(
sm
.
db
.
get
()
));
}
}
...
...
@@ -65,7 +65,8 @@ public:
return
rocksdb
::
Status
::
NotFound
();
}
return
writeBatchWithIndex
.
GetFromBatchAndDB
(
stateMachine
.
db
,
rocksdb
::
ReadOptions
(),
slice
,
&
value
);
return
writeBatchWithIndex
.
GetFromBatchAndDB
(
stateMachine
.
db
.
get
(),
rocksdb
::
ReadOptions
(),
slice
,
&
value
);
}
rocksdb
::
Status
exists
(
const
rocksdb
::
Slice
&
slice
)
{
...
...
@@ -80,7 +81,7 @@ public:
}
rocksdb
::
PinnableSlice
ignored
;
return
writeBatchWithIndex
.
GetFromBatchAndDB
(
stateMachine
.
db
,
rocksdb
::
ReadOptions
(),
slice
,
&
ignored
);
return
writeBatchWithIndex
.
GetFromBatchAndDB
(
stateMachine
.
db
.
get
()
,
rocksdb
::
ReadOptions
(),
slice
,
&
ignored
);
}
rocksdb
::
Status
get
(
const
rocksdb
::
Slice
&
slice
,
std
::
string
&
value
)
{
...
...
@@ -92,7 +93,7 @@ public:
return
stateMachine
.
db
->
Get
(
snapshot
->
opts
(),
slice
,
&
value
);
}
return
writeBatchWithIndex
.
GetFromBatchAndDB
(
stateMachine
.
db
,
rocksdb
::
ReadOptions
(),
slice
,
&
value
);
return
writeBatchWithIndex
.
GetFromBatchAndDB
(
stateMachine
.
db
.
get
()
,
rocksdb
::
ReadOptions
(),
slice
,
&
value
);
}
void
put
(
const
rocksdb
::
Slice
&
slice
,
const
rocksdb
::
Slice
&
value
)
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment