Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Yuta HIGUCHI
2014-11-06 22:17:37 -0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a7680a34484ab8554690abd25e107fd6bfbfb2bd
a7680a34
1 parent
2ee20002
snapshot compression
Change-Id: I0de15a66a129d2966a196b2de5491456aacc20e2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
2 deletions
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseStateMachine.java
core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseStateMachine.java
View file @
a7680a3
...
...
@@ -2,10 +2,14 @@ package org.onlab.onos.store.service.impl;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.zip.DeflaterOutputStream
;
import
java.util.zip.InflaterInputStream
;
import
net.kuujo.copycat.Command
;
import
net.kuujo.copycat.Query
;
...
...
@@ -23,6 +27,7 @@ import org.slf4j.Logger;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.Maps
;
import
com.google.common.io.ByteStreams
;
/**
* StateMachine whose transitions are coordinated/replicated
...
...
@@ -50,6 +55,8 @@ public class DatabaseStateMachine implements StateMachine {
private
State
state
=
new
State
();
private
boolean
compressSnapshot
=
false
;
@Command
public
boolean
createTable
(
String
tableName
)
{
return
state
.
getTables
().
putIfAbsent
(
tableName
,
Maps
.
newHashMap
())
==
null
;
...
...
@@ -214,7 +221,16 @@ public class DatabaseStateMachine implements StateMachine {
@Override
public
byte
[]
takeSnapshot
()
{
try
{
return
SERIALIZER
.
encode
(
state
);
if
(
compressSnapshot
)
{
byte
[]
input
=
SERIALIZER
.
encode
(
state
);
ByteArrayOutputStream
comp
=
new
ByteArrayOutputStream
(
input
.
length
);
DeflaterOutputStream
compressor
=
new
DeflaterOutputStream
(
comp
);
compressor
.
write
(
input
,
0
,
input
.
length
);
compressor
.
close
();
return
comp
.
toByteArray
();
}
else
{
return
SERIALIZER
.
encode
(
state
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"Failed to take snapshot"
,
e
);
throw
new
SnapshotException
(
e
);
...
...
@@ -224,7 +240,14 @@ public class DatabaseStateMachine implements StateMachine {
@Override
public
void
installSnapshot
(
byte
[]
data
)
{
try
{
this
.
state
=
SERIALIZER
.
decode
(
data
);
if
(
compressSnapshot
)
{
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
data
);
InflaterInputStream
decompressor
=
new
InflaterInputStream
(
in
);
ByteStreams
.
toByteArray
(
decompressor
);
this
.
state
=
SERIALIZER
.
decode
(
ByteStreams
.
toByteArray
(
decompressor
));
}
else
{
this
.
state
=
SERIALIZER
.
decode
(
data
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"Failed to install from snapshot"
,
e
);
throw
new
SnapshotException
(
e
);
...
...
Please
register
or
login
to post a comment