Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
e87973cd
R
rocksdb
项目概览
kvdb
/
rocksdb
11 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rocksdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e87973cd
编写于
5月 18, 2014
作者:
A
Ankit Gupta
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removing code from portal.h for setting handle of RestoreOptions and RestoreBackupableDB
上级
29eef1f8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
54 addition
and
120 deletion
+54
-120
java/org/rocksdb/BackupableDBOptions.java
java/org/rocksdb/BackupableDBOptions.java
+11
-11
java/org/rocksdb/RestoreBackupableDB.java
java/org/rocksdb/RestoreBackupableDB.java
+15
-14
java/org/rocksdb/RestoreOptions.java
java/org/rocksdb/RestoreOptions.java
+8
-7
java/org/rocksdb/test/BackupableDBTest.java
java/org/rocksdb/test/BackupableDBTest.java
+3
-1
java/rocksjni/portal.h
java/rocksjni/portal.h
+0
-66
java/rocksjni/restorejni.cc
java/rocksjni/restorejni.cc
+17
-21
未找到文件。
java/org/rocksdb/BackupableDBOptions.java
浏览文件 @
e87973cd
...
...
@@ -11,26 +11,26 @@ package org.rocksdb;
*
* Note that dispose() must be called before an Options instance
* become out-of-scope to release the allocated memory in c++.
*
*
* @param path Where to keep the backup files. Has to be different than dbname.
Best to set this to dbname_ + "/backups"
* @param shareTableFiles If share_table_files == true, backup will assume that
* table files with same name have the same contents. This enables
* incremental backups and avoids unnecessary data copies. If
* share_table_files == false, each backup will be on its own and will not
* @param shareTableFiles If share_table_files == true, backup will assume that
* table files with same name have the same contents. This enables
* incremental backups and avoids unnecessary data copies. If
* share_table_files == false, each backup will be on its own and will not
* share any data with other backups. default: true
* @param sync If sync == true, we can guarantee you'll get consistent backup
* even on a machine crash/reboot. Backup process is slower with sync
* @param sync If sync == true, we can guarantee you'll get consistent backup
* even on a machine crash/reboot. Backup process is slower with sync
* enabled. If sync == false, we don't guarantee anything on machine reboot.
* However, chances are some of the backups are consistent. Default: true
* @param destroyOldData If true, it will delete whatever backups there are
* @param destroyOldData If true, it will delete whatever backups there are
* already. Default: false
* @param backupLogFiles If false, we won't backup log files. This option can be
* useful for backing up in-memory databases where log file are persisted,
* useful for backing up in-memory databases where log file are persisted,
* but table files are in memory. Default: true
* @param backupRateLimit Max bytes that can be transferred in a second during
* @param backupRateLimit Max bytes that can be transferred in a second during
* backup. If 0, go as fast as you can. Default: 0
* @param restoreRateLimit Max bytes that can be transferred in a second during
* @param restoreRateLimit Max bytes that can be transferred in a second during
* restore. If 0, go as fast as you can. Default: 0
*/
public
class
BackupableDBOptions
extends
RocksObject
{
...
...
java/org/rocksdb/RestoreBackupableDB.java
浏览文件 @
e87973cd
...
...
@@ -7,24 +7,24 @@ package org.rocksdb;
/**
* This class is used to access information about backups and restore from them.
*
* Note that dispose() must be called before this instance become out-of-scope
*
* Note that dispose() must be called before this instance become out-of-scope
* to release the allocated memory in c++.
*
*
* @param options Instance of BackupableDBOptions.
*/
public
class
RestoreBackupableDB
extends
RocksObject
{
public
RestoreBackupableDB
(
BackupableDBOptions
options
)
{
super
();
newRestoreBackupableDB
(
options
.
nativeHandle_
);
n
ativeHandle_
=
n
ewRestoreBackupableDB
(
options
.
nativeHandle_
);
}
/**
* Restore from backup with backup_id
* IMPORTANT -- if options_.share_table_files == true and you restore DB
* from some backup that is not the latest, and you start creating new
* backups from the new DB, they will probably fail.
*
*
* Example: Let's say you have backups 1, 2, 3, 4, 5 and you restore 3.
* If you add new data to the DB and try creating a new backup now, the
* database will diverge from backups 4 and 5 and the new backup will fail.
...
...
@@ -36,7 +36,7 @@ public class RestoreBackupableDB extends RocksObject {
restoreDBFromBackup0
(
nativeHandle_
,
backupId
,
dbDir
,
walDir
,
restoreOptions
.
nativeHandle_
);
}
/**
* Restore from the latest backup.
*/
...
...
@@ -45,25 +45,25 @@ public class RestoreBackupableDB extends RocksObject {
restoreDBFromLatestBackup0
(
nativeHandle_
,
dbDir
,
walDir
,
restoreOptions
.
nativeHandle_
);
}
/**
* Deletes old backups, keeping latest numBackupsToKeep alive.
*
*
* @param Number of latest backups to keep
*/
public
void
purgeOldBackups
(
int
numBackupsToKeep
)
throws
RocksDBException
{
purgeOldBackups0
(
nativeHandle_
,
numBackupsToKeep
);
}
/**
* Deletes a specific backup.
*
*
* @param ID of backup to delete.
*/
public
void
deleteBackup
(
long
backupId
)
throws
RocksDBException
{
deleteBackup0
(
nativeHandle_
,
backupId
);
}
/**
* Release the memory allocated for the current instance
* in the c++ side.
...
...
@@ -71,10 +71,11 @@ public class RestoreBackupableDB extends RocksObject {
@Override
public
synchronized
void
dispose
()
{
if
(
isInitialized
())
{
dispose
(
nativeHandle_
);
nativeHandle_
=
0
;
}
}
private
native
void
newRestoreBackupableDB
(
long
options
);
private
native
long
newRestoreBackupableDB
(
long
options
);
private
native
void
restoreDBFromBackup0
(
long
nativeHandle
,
long
backupId
,
String
dbDir
,
String
walDir
,
long
restoreOptions
)
throws
RocksDBException
;
private
native
void
restoreDBFromLatestBackup0
(
long
nativeHandle
,
...
...
java/org/rocksdb/RestoreOptions.java
浏览文件 @
e87973cd
...
...
@@ -8,21 +8,21 @@ package org.rocksdb;
/**
* RestoreOptions to control the behavior of restore.
*
* Note that dispose() must be called before this instance become out-of-scope
* Note that dispose() must be called before this instance become out-of-scope
* to release the allocated memory in c++.
*
*
* @param If true, restore won't overwrite the existing log files in wal_dir. It
* will also move all log files from archive directory to wal_dir. Use this
* option in combination with BackupableDBOptions::backup_log_files = false
* option in combination with BackupableDBOptions::backup_log_files = false
* for persisting in-memory databases.
* Default: false
*/
public
class
RestoreOptions
extends
RocksObject
{
public
RestoreOptions
(
boolean
keepLogFiles
)
{
super
();
newRestoreOptions
(
keepLogFiles
);
n
ativeHandle_
=
n
ewRestoreOptions
(
keepLogFiles
);
}
/**
* Release the memory allocated for the current instance
* in the c++ side.
...
...
@@ -30,9 +30,10 @@ public class RestoreOptions extends RocksObject {
@Override
public
synchronized
void
dispose
()
{
if
(
isInitialized
())
{
dispose
(
nativeHandle_
);
nativeHandle_
=
0
;
}
}
private
native
void
newRestoreOptions
(
boolean
keepLogFiles
);
private
native
long
newRestoreOptions
(
boolean
keepLogFiles
);
private
native
void
dispose
(
long
handle
);
}
java/org/rocksdb/test/BackupableDBTest.java
浏览文件 @
e87973cd
...
...
@@ -36,10 +36,12 @@ public class BackupableDBTest {
bdb
.
close
();
// restore from backup
RestoreOptions
ropt
=
new
RestoreOptions
(
false
);
RestoreBackupableDB
rdb
=
new
RestoreBackupableDB
(
bopt
);
rdb
.
restoreDBFromLatestBackup
(
db_path
,
db_path
,
new
RestoreOptions
(
false
)
);
ropt
);
rdb
.
dispose
();
ropt
.
dispose
();
// verify that backed up data contains deleted record
bdb
=
BackupableDB
.
open
(
opt
,
bopt
,
db_path
);
...
...
java/rocksjni/portal.h
浏览文件 @
e87973cd
...
...
@@ -251,72 +251,6 @@ class BackupableDBOptionsJni {
}
};
class
RestoreOptionsJni
{
public:
// Get the java class id of org.rocksdb.RestoreOptions.
static
jclass
getJClass
(
JNIEnv
*
env
)
{
static
jclass
jclazz
=
env
->
FindClass
(
"org/rocksdb/RestoreOptions"
);
assert
(
jclazz
!=
nullptr
);
return
jclazz
;
}
// Get the field id of the member variable of org.rocksdb.RestoreOptions
// that stores the pointer to rocksdb::RestoreOptions
static
jfieldID
getHandleFieldID
(
JNIEnv
*
env
)
{
static
jfieldID
fid
=
env
->
GetFieldID
(
getJClass
(
env
),
"nativeHandle_"
,
"J"
);
assert
(
fid
!=
nullptr
);
return
fid
;
}
// Get the pointer to rocksdb::RestoreOptions
static
rocksdb
::
RestoreOptions
*
getHandle
(
JNIEnv
*
env
,
jobject
jobj
)
{
return
reinterpret_cast
<
rocksdb
::
RestoreOptions
*>
(
env
->
GetLongField
(
jobj
,
getHandleFieldID
(
env
)));
}
// Pass the rocksdb::RestoreOptions pointer to the java side.
static
void
setHandle
(
JNIEnv
*
env
,
jobject
jobj
,
rocksdb
::
RestoreOptions
*
op
)
{
env
->
SetLongField
(
jobj
,
getHandleFieldID
(
env
),
reinterpret_cast
<
jlong
>
(
op
));
}
};
class
RestoreBackupableDBJni
{
public:
// Get the java class id of org.rocksdb.RestoreBackupableDB.
static
jclass
getJClass
(
JNIEnv
*
env
)
{
static
jclass
jclazz
=
env
->
FindClass
(
"org/rocksdb/RestoreBackupableDB"
);
assert
(
jclazz
!=
nullptr
);
return
jclazz
;
}
// Get the field id of the member variable of org.rocksdb.RestoreBackupableDB
// that stores the pointer to rocksdb::RestoreBackupableDB
static
jfieldID
getHandleFieldID
(
JNIEnv
*
env
)
{
static
jfieldID
fid
=
env
->
GetFieldID
(
getJClass
(
env
),
"nativeHandle_"
,
"J"
);
assert
(
fid
!=
nullptr
);
return
fid
;
}
// Get the pointer to rocksdb::RestoreBackupableDB
static
rocksdb
::
RestoreBackupableDB
*
getHandle
(
JNIEnv
*
env
,
jobject
jobj
)
{
return
reinterpret_cast
<
rocksdb
::
RestoreBackupableDB
*>
(
env
->
GetLongField
(
jobj
,
getHandleFieldID
(
env
)));
}
// Pass the rocksdb::RestoreBackupableDB pointer to the java side.
static
void
setHandle
(
JNIEnv
*
env
,
jobject
jobj
,
rocksdb
::
RestoreBackupableDB
*
op
)
{
env
->
SetLongField
(
jobj
,
getHandleFieldID
(
env
),
reinterpret_cast
<
jlong
>
(
op
));
}
};
class
IteratorJni
{
public:
// Get the java class id of org.rocksdb.Iteartor.
...
...
java/rocksjni/restorejni.cc
浏览文件 @
e87973cd
...
...
@@ -4,7 +4,7 @@
// of patent rights can be found in the PATENTS file in the same directory.
//
// This file implements the "bridge" between Java and C++ and enables
// calling c++ rocksdb::RestoreBackupableDB and rocksdb::RestoreOptions methods
// calling c++ rocksdb::RestoreBackupableDB and rocksdb::RestoreOptions methods
// from Java side.
#include <stdio.h>
...
...
@@ -20,12 +20,12 @@
/*
* Class: org_rocksdb_RestoreOptions
* Method: newRestoreOptions
* Signature: (Z)
V
* Signature: (Z)
J
*/
void
Java_org_rocksdb_RestoreOptions_newRestoreOptions
(
JNIEnv
*
env
,
jlong
Java_org_rocksdb_RestoreOptions_newRestoreOptions
(
JNIEnv
*
env
,
jobject
jobj
,
jboolean
keep_log_files
)
{
auto
ropt
=
new
rocksdb
::
RestoreOptions
(
keep_log_files
);
r
ocksdb
::
RestoreOptionsJni
::
setHandle
(
env
,
jobj
,
ropt
);
r
eturn
reinterpret_cast
<
jlong
>
(
ropt
);
}
/*
...
...
@@ -38,20 +38,18 @@ void Java_org_rocksdb_RestoreOptions_dispose(JNIEnv* env, jobject jobj,
auto
ropt
=
reinterpret_cast
<
rocksdb
::
RestoreOptions
*>
(
jhandle
);
assert
(
ropt
);
delete
ropt
;
rocksdb
::
RestoreOptionsJni
::
setHandle
(
env
,
jobj
,
nullptr
);
}
/*
* Class: org_rocksdb_RestoreBackupableDB
* Method: newRestoreBackupableDB
* Signature: (J)
V
* Signature: (J)
J
*/
void
Java_org_rocksdb_RestoreBackupableDB_newRestoreBackupableDB
(
JNIEnv
*
env
,
jlong
Java_org_rocksdb_RestoreBackupableDB_newRestoreBackupableDB
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
jopt_handle
)
{
auto
opt
=
reinterpret_cast
<
rocksdb
::
BackupableDBOptions
*>
(
jopt_handle
);
auto
rdb
=
new
rocksdb
::
RestoreBackupableDB
(
rocksdb
::
Env
::
Default
(),
*
opt
);
r
ocksdb
::
RestoreBackupableDBJni
::
setHandle
(
env
,
jobj
,
rdb
);
r
eturn
reinterpret_cast
<
jlong
>
(
rdb
);
}
/*
...
...
@@ -63,17 +61,17 @@ void Java_org_rocksdb_RestoreBackupableDB_restoreDBFromBackup0(JNIEnv* env,
jobject
jobj
,
jlong
jhandle
,
jlong
jbackup_id
,
jstring
jdb_dir
,
jstring
jwal_dir
,
jlong
jopt_handle
)
{
auto
opt
=
reinterpret_cast
<
rocksdb
::
RestoreOptions
*>
(
jopt_handle
);
const
char
*
cdb_dir
=
env
->
GetStringUTFChars
(
jdb_dir
,
0
);
const
char
*
cwal_dir
=
env
->
GetStringUTFChars
(
jwal_dir
,
0
);
auto
rdb
=
reinterpret_cast
<
rocksdb
::
RestoreBackupableDB
*>
(
jhandle
);
rocksdb
::
Status
s
=
rdb
->
RestoreDBFromBackup
(
jbackup_id
,
cdb_dir
,
cwal_dir
,
*
opt
);
env
->
ReleaseStringUTFChars
(
jdb_dir
,
cdb_dir
);
env
->
ReleaseStringUTFChars
(
jwal_dir
,
cwal_dir
);
if
(
!
s
.
ok
())
{
rocksdb
::
RocksDBExceptionJni
::
ThrowNew
(
env
,
s
);
}
...
...
@@ -88,17 +86,17 @@ void Java_org_rocksdb_RestoreBackupableDB_restoreDBFromLatestBackup0(
JNIEnv
*
env
,
jobject
jobj
,
jlong
jhandle
,
jstring
jdb_dir
,
jstring
jwal_dir
,
jlong
jopt_handle
)
{
auto
opt
=
reinterpret_cast
<
rocksdb
::
RestoreOptions
*>
(
jopt_handle
);
const
char
*
cdb_dir
=
env
->
GetStringUTFChars
(
jdb_dir
,
0
);
const
char
*
cwal_dir
=
env
->
GetStringUTFChars
(
jwal_dir
,
0
);
auto
rdb
=
reinterpret_cast
<
rocksdb
::
RestoreBackupableDB
*>
(
jhandle
);
rocksdb
::
Status
s
=
rdb
->
RestoreDBFromLatestBackup
(
cdb_dir
,
cwal_dir
,
*
opt
);
env
->
ReleaseStringUTFChars
(
jdb_dir
,
cdb_dir
);
env
->
ReleaseStringUTFChars
(
jwal_dir
,
cwal_dir
);
if
(
!
s
.
ok
())
{
rocksdb
::
RocksDBExceptionJni
::
ThrowNew
(
env
,
s
);
}
...
...
@@ -113,7 +111,7 @@ void Java_org_rocksdb_RestoreBackupableDB_purgeOldBackups0(JNIEnv* env,
jobject
jobj
,
jlong
jhandle
,
jint
jnum_backups_to_keep
)
{
auto
rdb
=
reinterpret_cast
<
rocksdb
::
RestoreBackupableDB
*>
(
jhandle
);
rocksdb
::
Status
s
=
rdb
->
PurgeOldBackups
(
jnum_backups_to_keep
);
if
(
!
s
.
ok
())
{
rocksdb
::
RocksDBExceptionJni
::
ThrowNew
(
env
,
s
);
}
...
...
@@ -128,7 +126,7 @@ void Java_org_rocksdb_RestoreBackupableDB_deleteBackup0(JNIEnv* env,
jobject
jobj
,
jlong
jhandle
,
jlong
jbackup_id
)
{
auto
rdb
=
reinterpret_cast
<
rocksdb
::
RestoreBackupableDB
*>
(
jhandle
);
rocksdb
::
Status
s
=
rdb
->
DeleteBackup
(
jbackup_id
);
if
(
!
s
.
ok
())
{
rocksdb
::
RocksDBExceptionJni
::
ThrowNew
(
env
,
s
);
}
...
...
@@ -144,6 +142,4 @@ void Java_org_rocksdb_RestoreBackupableDB_dispose(JNIEnv* env, jobject jobj,
auto
ropt
=
reinterpret_cast
<
rocksdb
::
RestoreBackupableDB
*>
(
jhandle
);
assert
(
ropt
);
delete
ropt
;
rocksdb
::
RestoreBackupableDBJni
::
setHandle
(
env
,
jobj
,
nullptr
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录