Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
39fba2a1
Commit
39fba2a1
authored
May 06, 2013
by
Mukund Sivaraman
Browse files
[2850] Add a sync() method and make reset() and the destructor call it
This is so that checksums and such are synchronized.
parent
55779489
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/datasrc/memory/zone_table_segment_mapped.cc
View file @
39fba2a1
...
...
@@ -41,6 +41,10 @@ ZoneTableSegmentMapped::ZoneTableSegmentMapped(const RRClass& rrclass) :
{
}
ZoneTableSegmentMapped
::~
ZoneTableSegmentMapped
()
{
sync
();
}
bool
ZoneTableSegmentMapped
::
processChecksum
(
MemorySegmentMapped
&
segment
,
bool
create
,
...
...
@@ -259,6 +263,8 @@ ZoneTableSegmentMapped::reset(MemorySegmentOpenMode mode,
// mapped file. We cannot do this in many mode combinations
// unless we close the existing mapped file. So just close it.
clear
();
}
else
{
sync
();
}
switch
(
mode
)
{
...
...
@@ -278,28 +284,33 @@ ZoneTableSegmentMapped::reset(MemorySegmentOpenMode mode,
current_filename_
=
filename
;
}
void
ZoneTableSegmentMapped
::
sync
()
{
// Synchronize checksum, etc.
if
(
mem_sgmt_
&&
isWritable
())
{
// If there is a previously opened segment, and it was opened in
// read-write mode, update its checksum.
mem_sgmt_
->
shrinkToFit
();
const
MemorySegment
::
NamedAddressResult
result
=
mem_sgmt_
->
getNamedAddress
(
ZONE_TABLE_CHECKSUM_NAME
);
assert
(
result
.
first
);
assert
(
result
.
second
);
size_t
*
checksum
=
static_cast
<
size_t
*>
(
result
.
second
);
// First, clear the checksum so that getCheckSum() returns a
// consistent value.
*
checksum
=
0
;
const
size_t
new_checksum
=
mem_sgmt_
->
getCheckSum
();
// Now, update it into place.
*
checksum
=
new_checksum
;
}
}
void
ZoneTableSegmentMapped
::
clear
()
{
if
(
mem_sgmt_
)
{
if
(
isWritable
())
{
// If there is a previously opened segment, and it was
// opened in read-write mode, update its checksum.
mem_sgmt_
->
shrinkToFit
();
const
MemorySegment
::
NamedAddressResult
result
=
mem_sgmt_
->
getNamedAddress
(
ZONE_TABLE_CHECKSUM_NAME
);
assert
(
result
.
first
);
assert
(
result
.
second
);
uint32_t
*
checksum
=
static_cast
<
uint32_t
*>
(
result
.
second
);
// First, clear the checksum so that getCheckSum() returns
// a consistent value.
*
checksum
=
0
;
const
uint32_t
new_checksum
=
mem_sgmt_
->
getCheckSum
();
// Now, update it into place.
*
checksum
=
new_checksum
;
}
// Close the segment here in case the code further below
// doesn't complete successfully.
sync
();
header_
=
NULL
;
mem_sgmt_
.
reset
();
}
...
...
src/lib/datasrc/memory/zone_table_segment_mapped.h
View file @
39fba2a1
...
...
@@ -43,6 +43,9 @@ protected:
ZoneTableSegmentMapped
(
const
isc
::
dns
::
RRClass
&
rrclass
);
public:
/// \brief Destructor
virtual
~
ZoneTableSegmentMapped
();
/// \brief Return the ZoneTableHeader for the mapped zone table
/// segment implementation.
///
...
...
@@ -105,6 +108,8 @@ public:
virtual
void
clear
();
private:
void
sync
();
bool
processChecksum
(
isc
::
util
::
MemorySegmentMapped
&
segment
,
bool
create
,
std
::
string
&
error_msg
);
bool
processHeader
(
isc
::
util
::
MemorySegmentMapped
&
segment
,
bool
create
,
...
...
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