Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
d559fe66
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d559fe66
编写于
10月 10, 2017
作者:
K
Kevin Heifner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Switched to blocking queue to avoid busy wait #172
上级
72cecfcc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
21 deletion
+57
-21
plugins/db_plugin/CMakeLists.txt
plugins/db_plugin/CMakeLists.txt
+18
-1
plugins/db_plugin/db_plugin.cpp
plugins/db_plugin/db_plugin.cpp
+30
-17
plugins/db_plugin/include/eos/db_plugin/db_plugin.hpp
plugins/db_plugin/include/eos/db_plugin/db_plugin.hpp
+9
-3
未找到文件。
plugins/db_plugin/CMakeLists.txt
浏览文件 @
d559fe66
...
@@ -6,7 +6,6 @@ add_library( db_plugin
...
@@ -6,7 +6,6 @@ add_library( db_plugin
find_package
(
libmongoc-1.0 1.8
)
find_package
(
libmongoc-1.0 1.8
)
if
(
libmongoc-1.0_FOUND
)
if
(
libmongoc-1.0_FOUND
)
message
(
"-- mongoc found version
\"
${
MONGOC_VERSION
}
\"
"
)
message
(
"-- mongoc found version
\"
${
MONGOC_VERSION
}
\"
"
)
message
(
"-- mongoc include path
\"
${
MONGOC_INCLUDE_DIRS
}
\"
"
)
message
(
"-- mongoc include path
\"
${
MONGOC_INCLUDE_DIRS
}
\"
"
)
message
(
"-- mongoc libraries
\"
${
MONGOC_LIBRARIES
}
\"
"
)
message
(
"-- mongoc libraries
\"
${
MONGOC_LIBRARIES
}
\"
"
)
...
@@ -24,6 +23,24 @@ if (libmongoc-1.0_FOUND)
...
@@ -24,6 +23,24 @@ if (libmongoc-1.0_FOUND)
${
BSONCXX_LIBRARY_DIRS
}
${
BSONCXX_LIBRARY_DIRS
}
)
)
add_definitions
(
-DMONGODB
)
add_definitions
(
-DMONGODB
)
else
()
message
(
"Could NOT find MongoDB. db_plugin with MongoDB support will not be included."
)
# sudo apt-get install pkg-config libssl-dev libsasl2-dev
# wget https://github.com/mongodb/mongo-c-driver/releases/download/1.8.0/mongo-c-driver-1.8.0.tar.gz
# tar xzf mongo-c-driver-1.8.0.tar.gz
# cd mongo-c-driver-1.8.0
# ./configure --disable-automatic-init-and-cleanup --enable-static
# make
# sudo make install
#
# git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/stable --depth 1
# cd mongo-cxx-driver/build
# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
# sudo make EP_mnmlstc_core
# make
# sudo make install
#
# sudo apt-get install mongodb
endif
()
endif
()
target_include_directories
(
db_plugin
target_include_directories
(
db_plugin
...
...
plugins/db_plugin/db_plugin.cpp
浏览文件 @
d559fe66
...
@@ -9,7 +9,10 @@
...
@@ -9,7 +9,10 @@
#include <fc/variant.hpp>
#include <fc/variant.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/thread.hpp>
#include <boost/lockfree/spsc_queue.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <queue>
#ifdef MONGODB
#ifdef MONGODB
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
...
@@ -64,10 +67,12 @@ public:
...
@@ -64,10 +67,12 @@ public:
size_t
queue_size
=
0
;
size_t
queue_size
=
0
;
size_t
processed
=
0
;
size_t
processed
=
0
;
std
::
unique_ptr
<
boost
::
lockfree
::
spsc_queue
<
signed_block
>>
queue
;
std
::
queue
<
signed_block
>
queue
;
boost
::
mutex
mtx
;
boost
::
condition_variable
condtion
;
boost
::
thread
consum_thread
;
boost
::
thread
consum_thread
;
boost
::
atomic
<
bool
>
startup
{
true
};
boost
::
atomic
<
bool
>
done
{
false
};
boost
::
atomic
<
bool
>
done
{
false
};
boost
::
atomic
<
bool
>
startup
{
true
};
void
consum_blocks
();
void
consum_blocks
();
...
@@ -109,29 +114,36 @@ void db_plugin_impl::applied_irreversible_block(const signed_block& block) {
...
@@ -109,29 +114,36 @@ void db_plugin_impl::applied_irreversible_block(const signed_block& block) {
// on startup we don't want to queue, instead push back on caller
// on startup we don't want to queue, instead push back on caller
process_irreversible_block
(
block
);
process_irreversible_block
(
block
);
}
else
{
}
else
{
if
(
!
queue
->
push
(
block
))
{
boost
::
mutex
::
scoped_lock
lock
(
mtx
);
// TODO what to do if full
queue
.
push
(
block
);
elog
(
"queue is full!!!!!"
);
lock
.
unlock
();
FC_ASSERT
(
false
,
"queue is full"
);
condtion
.
notify_one
();
}
}
}
}
}
void
db_plugin_impl
::
consum_blocks
()
{
void
db_plugin_impl
::
consum_blocks
()
{
signed_block
block
;
signed_block
block
;
while
(
!
done
)
{
size_t
size
=
0
;
while
(
queue
->
pop
(
block
))
{
while
(
true
)
{
auto
available
=
queue
->
read_available
();
boost
::
mutex
::
scoped_lock
lock
(
mtx
);
while
(
queue
.
empty
()
&&
!
done
)
{
condtion
.
wait
(
lock
);
}
size
=
queue
.
size
();
if
(
size
>
0
)
{
block
=
queue
.
front
();
queue
.
pop
();
lock
.
unlock
();
// warn if queue size greater than 75%
// warn if queue size greater than 75%
if
(
availabl
e
>
(
queue_size
*
0.75
))
{
if
(
siz
e
>
(
queue_size
*
0.75
))
{
wlog
(
"queue size: ${q}"
,
(
"q"
,
availabl
e
+
1
));
wlog
(
"queue size: ${q}"
,
(
"q"
,
siz
e
+
1
));
}
}
process_irreversible_block
(
block
);
process_irreversible_block
(
block
);
continue
;
}
else
if
(
done
)
{
break
;
}
}
}
}
while
(
queue
->
pop
(
block
))
{
process_irreversible_block
(
block
);
}
ilog
(
"db_plugin consum thread shutdown gracefully"
);
ilog
(
"db_plugin consum thread shutdown gracefully"
);
}
}
...
@@ -485,6 +497,8 @@ db_plugin_impl::db_plugin_impl()
...
@@ -485,6 +497,8 @@ db_plugin_impl::db_plugin_impl()
db_plugin_impl
::~
db_plugin_impl
()
{
db_plugin_impl
::~
db_plugin_impl
()
{
try
{
try
{
done
=
true
;
done
=
true
;
condtion
.
notify_one
();
consum_thread
.
join
();
consum_thread
.
join
();
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
elog
(
"Exception on db_plugin shutdown of consum thread: ${e}"
,
(
"e"
,
e
.
what
()));
elog
(
"Exception on db_plugin shutdown of consum thread: ${e}"
,
(
"e"
,
e
.
what
()));
...
@@ -589,7 +603,6 @@ void db_plugin::plugin_initialize(const variables_map& options)
...
@@ -589,7 +603,6 @@ void db_plugin::plugin_initialize(const variables_map& options)
}
else
if
(
options
.
count
(
"queue-size"
))
{
}
else
if
(
options
.
count
(
"queue-size"
))
{
auto
size
=
options
.
at
(
"queue-size"
).
as
<
uint
>
();
auto
size
=
options
.
at
(
"queue-size"
).
as
<
uint
>
();
my
->
queue_size
=
size
;
my
->
queue_size
=
size
;
my
->
queue
=
std
::
make_unique
<
boost
::
lockfree
::
spsc_queue
<
signed_block
>>
(
size
);
}
}
std
::
string
uri
=
options
.
at
(
"mongodb-uri"
).
as
<
std
::
string
>
();
std
::
string
uri
=
options
.
at
(
"mongodb-uri"
).
as
<
std
::
string
>
();
...
...
plugins/db_plugin/include/eos/db_plugin/db_plugin.hpp
浏览文件 @
d559fe66
#pragma once
#pragma once
#include <eos/chain_plugin/chain_plugin.hpp>
#include <eos/chain_plugin/chain_plugin.hpp>
#include <eos/chain/block.hpp>
#include <appbase/application.hpp>
#include <appbase/application.hpp>
#include <memory>
#include <memory>
namespace
fc
{
class
variant
;
}
namespace
eos
{
namespace
eos
{
using
db_plugin_impl_ptr
=
std
::
shared_ptr
<
class
db_plugin_impl
>
;
using
db_plugin_impl_ptr
=
std
::
shared_ptr
<
class
db_plugin_impl
>
;
/**
* Provides persistence to MongoDB for:
* Blocks
* Transactions
* Messages
* Accounts
*
* See data dictionary (DB Schema Definition - EOS API) for description of MongoDB schema.
*/
class
db_plugin
:
public
plugin
<
db_plugin
>
{
class
db_plugin
:
public
plugin
<
db_plugin
>
{
public:
public:
APPBASE_PLUGIN_REQUIRES
((
chain_plugin
))
APPBASE_PLUGIN_REQUIRES
((
chain_plugin
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录