separate emulator/simulator into a separated tool as tools.emulator from tools.common

This commit is contained in:
Zhenyu Guo 2016-09-29 12:25:51 +08:00
Родитель 779cc6d518
Коммит f8d202a302
53 изменённых файлов: 1113 добавлений и 109 удалений

Просмотреть файл

@ -16,6 +16,7 @@ port = 23456
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.hpc
dsn.tools.nfs
dsn.dist.uri.resolver

Просмотреть файл

@ -5,6 +5,7 @@ package_dir = C:\work\rDSN\src\tools\webstudio\app_package\local\packages
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
dsn.dist.service.stateless

Просмотреть файл

@ -18,6 +18,7 @@ $default_serialize_format = $default_serialize_format."_".strtoupper($idl_format
?>
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
<?=$_PROG->name?>
@ -68,7 +69,7 @@ foreach ($_PROG->services as $svc)
start_nfs = true
tool = nativerun
;tool = simulator
;tool = emulator
;toollets = tracer
;toollets = tracer,profiler,fault_injector
pause_on_start = false

Просмотреть файл

@ -18,6 +18,7 @@ $default_serialize_format = $default_serialize_format."_".strtoupper($idl_format
?>
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
<?=$_PROG->name?>
@ -68,7 +69,7 @@ foreach ($_PROG->services as $svc)
start_nfs = true
tool = nativerun
;tool = simulator
;tool = emulator
;toollets = tracer
;toollets = tracer,profiler,fault_injector
pause_on_start = false

Просмотреть файл

@ -18,6 +18,7 @@ $default_serialize_format = $default_serialize_format."_".strtoupper($idl_format
?>
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
dsn.dist.service.meta_server
@ -92,7 +93,7 @@ stateful = true
start_nfs = true
tool = nativerun
;tool = simulator
;tool = emulator
toollets = tracer
;toollets = tracer,profiler,fault_injector
pause_on_start = false

Просмотреть файл

@ -56,7 +56,7 @@
* such as loggers, performance counters, etc.
* (5) rich debug, development tools and runtime policies support
* - tool API with task granularity semantic for further tool and runtime policy development.
* - rich existing tools, tracer, profiler, simulator, model checker, replayer, global checker
* - rich existing tools, tracer, profiler, emulator, model checker, replayer, global checker
* (7) PRINCIPLE: all non-determinims must be go through these system calls so that powerful
* internal tools are possible - replay, model checking, replication, ...,
* AND, it is still OK to call other DETERMINISTIC APIs for applications.

Просмотреть файл

@ -210,7 +210,7 @@ struct service_spec
};
CONFIG_BEGIN(service_spec)
CONFIG_FLD_STRING(tool, "", "use what tool to run this process, e.g., native or simulator")
CONFIG_FLD_STRING(tool, "", "use what tool to run this process, e.g., native or emulator")
CONFIG_FLD_STRING_LIST(toollets, "use what toollets, e.g., tracer, profiler, fault_injector")
CONFIG_FLD_STRING(data_dir, "./data", "where to put the all the data/log/coredump, etc..")
CONFIG_FLD(bool, bool, start_nfs, false, "whether to start nfs")

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
@ -36,7 +37,7 @@ count = 3
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER
[core]
;tool = simulator
;tool = emulator
tool = nativerun
;tool = fastrun
@ -52,7 +53,7 @@ io_mode = IOE_PER_NODE
;io_mode = IOE_PER_QUEUE
io_worker_count = 1
[tools.simulator]
[tools.emulator]
random_seed = 0
[network]

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.hpc
dsn.tools.nfs
@ -42,7 +43,7 @@ count = 1
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER
[core]
;tool = simulator
;tool = emulator
;tool = nativerun
tool = fastrun
@ -79,7 +80,7 @@ fast_flush = true
short_header = false
stderr_start_level = LOG_LEVEL_FATAL
[tools.simulator]
[tools.emulator]
random_seed = 0
[network]

Просмотреть файл

@ -254,8 +254,8 @@ TEST(core, dsn_file)
}
ASSERT_LT(0u, rin.sz);
ASSERT_EQ(rin.sz, dsn_file_get_io_size(tin));
// this is only true for simulator
if (dsn::tools::get_current_tool()->name() == "simulator")
// this is only true for emulator
if (dsn::tools::get_current_tool()->name() == "emulator")
{
ASSERT_EQ(1, dsn_task_get_ref(tin));
}
@ -278,8 +278,8 @@ TEST(core, dsn_file)
ASSERT_EQ(ERR_OK, dsn_task_error(tout));
ASSERT_EQ(rin.sz, rout.sz);
ASSERT_EQ(rin.sz, dsn_file_get_io_size(tout));
// this is only true for simulator
if (dsn::tools::get_current_tool()->name() == "simulator")
// this is only true for emulator
if (dsn::tools::get_current_tool()->name() == "emulator")
{
ASSERT_EQ(1, dsn_task_get_ref(tout));
}
@ -338,8 +338,8 @@ TEST(core, dsn_nfs)
ASSERT_EQ(ERR_OK, r.err);
ASSERT_EQ(r.sz, dsn_file_get_io_size(t));
ASSERT_EQ(0, r.sz);
// this is only true for simulator
if (dsn::tools::get_current_tool()->name() == "simulator")
// this is only true for emulator
if (dsn::tools::get_current_tool()->name() == "emulator")
{
ASSERT_EQ(1, dsn_task_get_ref(t));
}
@ -381,8 +381,8 @@ TEST(core, dsn_nfs)
ASSERT_EQ(ERR_OK, r.err);
ASSERT_EQ(r.sz, dsn_file_get_io_size(t));
ASSERT_EQ(0, r.sz);
// this is only true for simulator
if (dsn::tools::get_current_tool()->name() == "simulator")
// this is only true for emulator
if (dsn::tools::get_current_tool()->name() == "emulator")
{
ASSERT_EQ(1, dsn_task_get_ref(t));
}
@ -410,8 +410,8 @@ TEST(core, dsn_nfs)
ASSERT_EQ(ERR_OK, r.err);
ASSERT_EQ(r.sz, dsn_file_get_io_size(t));
ASSERT_EQ(0, r.sz);
// this is only true for simulator
if (dsn::tools::get_current_tool()->name() == "simulator")
// this is only true for emulator
if (dsn::tools::get_current_tool()->name() == "emulator")
{
ASSERT_EQ(1, dsn_task_get_ref(t));
}
@ -439,7 +439,7 @@ TEST(core, dsn_nfs)
TEST(core, dsn_env)
{
if(dsn::service_engine::fast_instance().spec().tool == "simulator")
if(dsn::service_engine::fast_instance().spec().tool == "emulator")
return;
uint64_t now1 = dsn_now_ns();
std::this_thread::sleep_for(std::chrono::milliseconds(1));

Просмотреть файл

@ -77,7 +77,7 @@ DEFINE_THREAD_POOL_CODE(THREAD_POOL_FOR_TEST_2)
TEST(core, task_engine)
{
if(dsn::service_engine::fast_instance().spec().tool == "simulator")
if(dsn::service_engine::fast_instance().spec().tool == "emulator")
return;
service_node* node = task::get_current_node2();

Просмотреть файл

@ -65,16 +65,16 @@ namespace dsn
struct tls_tracker_hack
{
unsigned int magic;
bool is_simulator;
bool is_emulator;
bool under_simulation()
bool under_emulation()
{
if (magic != 0xdeadbeef)
{
is_simulator = (dsn::tools::get_current_tool()->name() == "simulator");
is_emulator = (dsn::tools::get_current_tool()->name() == "emulator");
magic = 0xdeadbeef;
}
return is_simulator;
return is_emulator;
}
};
@ -108,7 +108,7 @@ namespace dsn
{
// tracker get the lock
case trackable_task::OWNER_DELETE_NOT_LOCKED:
if (s_hack.under_simulation())
if (s_hack.under_emulation())
{
tsk = (task*)(tcm->_task);
tsk->add_ref(); // released after delete commit
@ -156,7 +156,7 @@ namespace dsn
switch (prepare_state)
{
case trackable_task::OWNER_DELETE_NOT_LOCKED:
if (s_hack.under_simulation())
if (s_hack.under_emulation())
{
tsk = (task*)(tcm->_task);
tsk->add_ref(); // released after delete commit

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
[apps..default]
@ -48,7 +49,7 @@ count = 1
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER
[core]
;tool = simulator
;tool = emulator
tool = nativerun
;tool = fastrun
@ -73,7 +74,7 @@ fast_flush = true
short_header = false
stderr_start_level = LOG_LEVEL_FATAL
[tools.simulator]
[tools.emulator]
random_seed = 0
[network]

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
[apps..default]
@ -48,7 +49,7 @@ count = 1
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER
[core]
;tool = simulator
;tool = emulator
tool = nativerun
;tool = fastrun
@ -73,7 +74,7 @@ fast_flush = true
short_header = false
stderr_start_level = LOG_LEVEL_FATAL
[tools.simulator]
[tools.emulator]
random_seed = 0
[network]

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
[apps..default]
@ -48,7 +49,7 @@ count = 1
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER
[core]
;tool = simulator
;tool = emulator
tool = nativerun
;tool = fastrun
@ -73,7 +74,7 @@ fast_flush = true
short_header = false
stderr_start_level = LOG_LEVEL_FATAL
[tools.simulator]
[tools.emulator]
random_seed = 0
[network]

Просмотреть файл

@ -1,5 +1,6 @@
add_subdirectory(tools.common)
add_subdirectory(tools.nfs)
add_subdirectory(tools.emulator)
add_subdirectory(dist.uri.resolver)
add_subdirectory(apps.echo)
add_subdirectory(apps.skv)

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
@ -29,7 +30,7 @@ pools = THREAD_POOL_DEFAULT
[core]
tool = simulator
tool = emulator
;tool = nativerun
;toollets = tracer
;toollets = tracer, profiler, fault_injector
@ -37,7 +38,7 @@ pause_on_start = false
logging_factory_name = dsn::tools::screen_logger
[tools.simulator]
[tools.emulator]
random_seed = 0
[network]

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
@ -207,7 +208,7 @@ timer_factory_name =
; how many disk timer services? IOE_PER_NODE, or IOE_PER_QUEUE
timer_io_mode =
; use what tool to run this process, e.g., native or simulator
; use what tool to run this process, e.g., native or emulator
tool = nativerun
; use what toollets, e.g., tracer, profiler, fault_injector
@ -761,7 +762,7 @@ worker_priority =
worker_share_core = true
[tools.simulator]
[tools.emulator]
;
random_seed = 0

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
dsn.dist.service.meta_server

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
dsn.dist.service.meta_server
@ -73,7 +74,7 @@ per_thread_buffer_bytes = 20480000
start_nfs = true
data_dir = %data-dir%
;tool = simulator
;tool = emulator
tool = nativerun
;tool = fastrun
;toollets = tracer
@ -95,7 +96,7 @@ short_header = false
fast_flush = true
stderr_start_level = LOG_LEVEL_FATAL
[tools.simulator]
[tools.emulator]
random_seed = 0
;min_message_delay_microseconds = 0
;max_message_delay_microseconds = 0

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
dsn.dist.service.meta_server
@ -62,7 +63,7 @@ per_thread_buffer_bytes = 20480000
[core]
start_nfs = true
;tool = simulator
;tool = emulator
tool = nativerun
;tool = fastrun
;toollets = tracer
@ -84,7 +85,7 @@ short_header = false
fast_flush = true
stderr_start_level = LOG_LEVEL_FATAL
[tools.simulator]
[tools.emulator]
random_seed = 0
;min_message_delay_microseconds = 0
;max_message_delay_microseconds = 0

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
dsn.dist.service.meta_server
@ -63,7 +64,7 @@ per_thread_buffer_bytes = 2048000
[core]
start_nfs = true
tool = simulator
tool = emulator
;tool = nativerun
;tool = fastrun
;toollets = tracer
@ -79,7 +80,7 @@ pause_on_start = false
;logging_factory_name = dsn::tools::hpc_logger
;aio_factory_name = dsn::tools::empty_aio_provider
[tools.simulator]
[tools.emulator]
random_seed = 0
;min_message_delay_microseconds = 0
;max_message_delay_microseconds = 0

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
@ -42,7 +43,7 @@ per_thread_buffer_bytes = 2048000
[core]
start_nfs = true
tool = simulator
tool = emulator
;tool = nativerun
;tool = fastrun
toollets = tracer
@ -58,7 +59,7 @@ pause_on_start = false
;logging_factory_name = dsn::tools::hpc_logger
;aio_factory_name = dsn::tools::empty_aio_provider
[tools.simulator]
[tools.emulator]
random_seed = 0
;min_message_delay_microseconds = 0
;max_message_delay_microseconds = 0

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
dsn.dist.service.meta_server
@ -66,7 +67,7 @@ per_thread_buffer_bytes = 20480000
[core]
start_nfs = true
;tool = simulator
;tool = emulator
tool = nativerun
;tool = fastrun
;toollets = tracer
@ -89,7 +90,7 @@ short_header = false
fast_flush = true
stderr_start_level = LOG_LEVEL_FATAL
[tools.simulator]
[tools.emulator]
random_seed = 0
min_message_delay_microseconds = 0
max_message_delay_microseconds = 0

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
dsn.dist.service.meta_server
@ -63,7 +64,7 @@ per_thread_buffer_bytes = 10240000
[core]
start_nfs = true
;tool = simulator
;tool = emulator
tool = nativerun
;toollets = tracer
;toollets = fault_injector
@ -77,7 +78,7 @@ pause_on_start = false
;logging_factory_name = dsn::tools::hpc_tail_logger
;aio_factory_name = dsn::tools::empty_aio_provider
[tools.simulator]
[tools.emulator]
random_seed = 0
;min_message_delay_microseconds = 0
;max_message_delay_microseconds = 0

Просмотреть файл

@ -40,7 +40,6 @@
#include <dsn/tool_api.h>
#include "asio_net_provider.h"
#include "network.sim.h"
#include <dsn/cpp/test_utils.h>
//
//using namespace dsn;

Просмотреть файл

@ -45,7 +45,6 @@
# include "simple_perf_counter_v2_atomic.h"
# include "simple_perf_counter_v2_fast.h"
# include "simple_task_queue.h"
# include "network.sim.h"
# include "simple_logger.h"
# include "empty_aio_provider.h"
# include "dsn_message_parser.h"
@ -53,7 +52,6 @@
# include "http_message_parser.h"
# include "raw_message_parser.h"
# include "simulator.h"
# include "nativerun.h"
# include "tracer.h"
# include "profiler.h"
@ -74,7 +72,6 @@ namespace dsn {
register_component_provider<std_semaphore_provider>("dsn::tools::std_semaphore_provider");
register_component_provider<asio_network_provider>("dsn::tools::asio_network_provider");
register_component_provider<asio_udp_provider>("dsn::tools::asio_udp_provider");
register_component_provider<sim_network_provider>("dsn::tools::sim_network_provider");
register_component_provider<simple_task_queue>("dsn::tools::simple_task_queue");
register_component_provider<simple_timer_service>("dsn::tools::simple_timer_service");
@ -115,7 +112,6 @@ namespace dsn {
MODULE_INIT_BEGIN(tools_common)
dsn::tools::register_common_providers();
dsn::tools::register_tool<dsn::tools::nativerun>("nativerun");
dsn::tools::register_tool<dsn::tools::simulator>("simulator");
dsn::tools::register_toollet<dsn::tools::tracer>("tracer");
dsn::tools::register_toollet<dsn::tools::profiler>("profiler");
dsn::tools::register_toollet<dsn::tools::fault_injector>("fault_injector");

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
[apps..default]
@ -48,7 +49,7 @@ count = 1
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER
[core]
;tool = simulator
;tool = emulator
tool = nativerun
;tool = fastrun
@ -73,7 +74,7 @@ fast_flush = true
short_header = false
stderr_start_level = LOG_LEVEL_FATAL
[tools.simulator]
[tools.emulator]
random_seed = 0
[network]

Просмотреть файл

@ -0,0 +1,37 @@
if (DEFINED DSN_CMAKE_INCLUDED)
else()
set(DSN_ROOT "$ENV{DSN_ROOT}")
if(NOT EXISTS "${DSN_ROOT}/")
message(FATAL_ERROR "Please make sure that ${DSN_ROOT} exists.")
endif()
include("${DSN_ROOT}/bin/dsn.cmake")
endif()
set(MY_PROJ_NAME dsn.tools.emulator)
# Source files under CURRENT project directory will be automatically included.
# You can manually set MY_PROJ_SRC to include source files under other directories.
set(MY_PROJ_SRC "")
# Search mode for source files under CURRENT project directory?
# "GLOB_RECURSE" for recursive search
# "GLOB" for non-recursive search
set(MY_SRC_SEARCH_MODE "GLOB")
set(MY_PROJ_INC_PATH ${GTEST_INCLUDE_DIR})
set(MY_PROJ_LIBS gtest)
set(MY_BOOST_PACKAGES "")
set(MY_PROJ_LIB_PATH "")
# Extra files that will be installed
set(MY_BINPLACES "")
dsn_add_shared_library()
file(COPY test/ DESTINATION "${CMAKE_BINARY_DIR}/test/${MY_PROJ_NAME}")

Просмотреть файл

@ -39,9 +39,6 @@
#if defined(_WIN32)
#define NATIVE_AIO_PROVIDER native_win_aio_provider
#include "native_aio_provider.win.h"
#elif defined(__linux__)
#define NATIVE_AIO_PROVIDER native_linux_aio_provider
#include "native_aio_provider.linux.h"
#else
#define NATIVE_AIO_PROVIDER native_posix_aio_provider
#include "native_aio_provider.posix.h"

Просмотреть файл

@ -34,31 +34,19 @@
*/
# include "simulator.h"
# include "emulator.h"
# include "scheduler.h"
# include "diske.sim.h"
# include "env.sim.h"
# include "task_engine.sim.h"
# ifdef __TITLE__
# undef __TITLE__
# endif
# define __TITLE__ "tools.simulator"
# define __TITLE__ "tools.emulator"
namespace dsn { namespace tools {
void simulator::install(service_spec& spec)
void emulator::install(service_spec& spec)
{
register_component_provider<sim_aio_provider>("dsn::tools::sim_aio_provider");
register_component_provider<sim_env_provider>("dsn::tools::sim_env_provider");
register_component_provider<sim_task_queue>("dsn::tools::sim_task_queue");
register_component_provider<sim_timer_service>("dsn::tools::sim_timer_service");
register_component_provider<sim_semaphore_provider>("dsn::tools::sim_semaphore_provider");
register_component_provider<sim_lock_provider>("dsn::tools::sim_lock_provider");
register_component_provider<sim_lock_nr_provider>("dsn::tools::sim_lock_nr_provider");
register_component_provider<sim_rwlock_nr_provider>("dsn::tools::sim_rwlock_nr_provider");
scheduler::instance();
if (spec.aio_factory_name == "")
@ -124,19 +112,19 @@ void simulator::install(service_spec& spec)
}
sys_init_after_app_created.put_back(
simulator::on_system_init_for_add_global_checker,
emulator::on_system_init_for_add_global_checker,
"checkers.install"
);
sys_exit.put_front(simulator::on_system_exit, "simulator");
sys_exit.put_front(emulator::on_system_exit, "emulator");
}
void simulator::on_system_init_for_add_global_checker()
void emulator::on_system_init_for_add_global_checker()
{
safe_vector<global_checker> checkers;
::dsn::get_registered_checkers(checkers);
auto t = dynamic_cast<dsn::tools::simulator*>(::dsn::tools::get_current_tool());
auto t = dynamic_cast<dsn::tools::emulator*>(::dsn::tools::get_current_tool());
if (t != nullptr)
{
for (auto& c : checkers)
@ -146,19 +134,19 @@ void simulator::on_system_init_for_add_global_checker()
}
}
void simulator::on_system_exit(sys_exit_type st)
void emulator::on_system_exit(sys_exit_type st)
{
derror("system exits, you can replay this process using random seed %d",
sim_env_provider::seed()
);
}
void simulator::add_checker(const char* name, dsn_checker_create create, dsn_checker_apply apply)
void emulator::add_checker(const char* name, dsn_checker_create create, dsn_checker_apply apply)
{
scheduler::instance().add_checker(name, create, apply);
}
void simulator::run()
void emulator::run()
{
scheduler::instance().start();
tool_app::run();

Просмотреть файл

@ -26,7 +26,7 @@
/*
* Description:
* the simulation tool (include simulation, replay, model-checking, ...)
* the emulation tool (include emulation, replay, model-checking, ...)
*
* Revision history:
* Mar., 2015, @imzhenyu (Zhenyu Guo), first version
@ -39,10 +39,10 @@
namespace dsn { namespace tools {
class simulator : public tool_app
class emulator : public tool_app
{
public:
simulator(const char* name)
emulator(const char* name)
: tool_app(name)
{
}

Просмотреть файл

@ -39,7 +39,7 @@
# ifdef __TITLE__
# undef __TITLE__
# endif
# define __TITLE__ "env.provider.simulator"
# define __TITLE__ "env.provider.emulator"
namespace dsn { namespace tools {
@ -60,13 +60,13 @@ sim_env_provider::sim_env_provider(env_provider* inner_provider)
{
task_worker::on_start.put_front(on_worker_start, "sim_env_provider::on_worker_start");
_seed = (int)dsn_config_get_value_uint64("tools.simulator", "random_seed", 0, "random seed for the simulator, 0 for random random seed");
_seed = (int)dsn_config_get_value_uint64("tools.emulator", "random_seed", 0, "random seed for the emulator, 0 for random random seed");
if (_seed == 0)
{
_seed = std::random_device{}();
}
derror("simulation.random seed for this round is %d", _seed);
derror("[tools.emulator] random_seed for this round is %d", _seed);
}
}} // end namespace

Просмотреть файл

@ -45,7 +45,7 @@
# include "task_engine.sim.h"
# include "scheduler.h"
TEST(tools_simulator, dsn_semaphore)
TEST(tools_emulator, dsn_semaphore)
{
if(dsn::task::get_current_worker() == nullptr)
return;
@ -59,12 +59,12 @@ TEST(tools_simulator, dsn_semaphore)
dsn_semaphore_destroy(s);
}
TEST(tools_simulator, dsn_lock_nr)
TEST(tools_emulator, dsn_lock_nr)
{
if(dsn::task::get_current_worker() == nullptr)
return;
if (dsn::tools::get_current_tool()->name() != "simulator")
if (dsn::tools::get_current_tool()->name() != "emulator")
return;
dsn::tools::sim_lock_nr_provider* s = new dsn::tools::sim_lock_nr_provider(nullptr);
@ -76,12 +76,12 @@ TEST(tools_simulator, dsn_lock_nr)
}
TEST(tools_simulator, dsn_lock)
TEST(tools_emulator, dsn_lock)
{
if(dsn::task::get_current_worker() == nullptr)
return;
if (dsn::tools::get_current_tool()->name() != "simulator")
if (dsn::tools::get_current_tool()->name() != "emulator")
return;
dsn::tools::sim_lock_provider* s = new dsn::tools::sim_lock_provider(nullptr);
@ -95,12 +95,12 @@ TEST(tools_simulator, dsn_lock)
namespace dsn{ namespace test{
typedef std::function<void()> system_callback;
}}
TEST(tools_simulator, scheduler)
TEST(tools_emulator, scheduler)
{
if(dsn::task::get_current_worker() == nullptr)
return;
if (dsn::tools::get_current_tool()->name() != "simulator")
if (dsn::tools::get_current_tool()->name() != "emulator")
return;
dsn::tools::sim_worker_state* s = dsn::tools::scheduler::task_worker_ext::get(dsn::task::get_current_worker());

Просмотреть файл

@ -0,0 +1,59 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Microsoft Corporation
*
* -=- Robust Distributed System Nucleus (rDSN) -=-
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* Description:
* What is this file about?
*
* Revision history:
* xxxx-xx-xx, author, first version
* xxxx-xx-xx, author, fix bug about xxx
*/
# include <dsn/utility/module_init.cpp.h>
# include "emulator.h"
# include "diske.sim.h"
# include "env.sim.h"
# include "task_engine.sim.h"
# include "network.sim.h"
MODULE_INIT_BEGIN(tools_emulator)
::dsn::tools::register_component_provider< ::dsn::tools::sim_aio_provider>("dsn::tools::sim_aio_provider");
::dsn::tools::register_component_provider< ::dsn::tools::sim_network_provider>("dsn::tools::sim_network_provider");
::dsn::tools::register_component_provider< ::dsn::tools::sim_env_provider>("dsn::tools::sim_env_provider");
::dsn::tools::register_component_provider< ::dsn::tools::sim_task_queue>("dsn::tools::sim_task_queue");
::dsn::tools::register_component_provider< ::dsn::tools::sim_timer_service>("dsn::tools::sim_timer_service");
::dsn::tools::register_component_provider< ::dsn::tools::sim_semaphore_provider>("dsn::tools::sim_semaphore_provider");
::dsn::tools::register_component_provider< ::dsn::tools::sim_lock_provider>("dsn::tools::sim_lock_provider");
::dsn::tools::register_component_provider< ::dsn::tools::sim_lock_nr_provider>("dsn::tools::sim_lock_nr_provider");
::dsn::tools::register_component_provider< ::dsn::tools::sim_rwlock_nr_provider>("dsn::tools::sim_rwlock_nr_provider");
dsn::tools::register_tool<dsn::tools::emulator>("emulator");
// for legacy reasons
dsn::tools::register_tool<dsn::tools::emulator>("emulator");
MODULE_INIT_END

Просмотреть файл

@ -0,0 +1,237 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Microsoft Corporation
*
* -=- Robust Distributed System Nucleus (rDSN) -=-
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* Description:
* What is this file about?
*
* Revision history:
* xxxx-xx-xx, author, first version
* xxxx-xx-xx, author, fix bug about xxx
*/
# ifndef _WIN32
# include "native_aio_provider.posix.h"
# include <aio.h>
# include <fcntl.h>
# include <cstdlib>
# ifdef __TITLE__
# undef __TITLE__
# endif
# define __TITLE__ "aio.provider.posix"
namespace dsn {
namespace tools {
native_posix_aio_provider::native_posix_aio_provider(disk_engine* disk, aio_provider* inner_provider)
: aio_provider(disk, inner_provider)
{
}
native_posix_aio_provider::~native_posix_aio_provider()
{
}
dsn_handle_t native_posix_aio_provider::open(const char* file_name, int flag, int pmode)
{
dsn_handle_t fh = (dsn_handle_t)(uintptr_t)::open(file_name, flag, pmode);
if (fh == DSN_INVALID_FILE_HANDLE)
{
derror("create file failed, err = %s", strerror(errno));
}
return fh;
}
error_code native_posix_aio_provider::close(dsn_handle_t fh)
{
if (fh == DSN_INVALID_FILE_HANDLE || ::close((int)(uintptr_t)(fh)) == 0)
{
return ERR_OK;
}
else
{
derror("close file failed, err = %s", strerror(errno));
return ERR_FILE_OPERATION_FAILED;
}
}
error_code native_posix_aio_provider::flush(dsn_handle_t fh)
{
if (fh == DSN_INVALID_FILE_HANDLE || ::fsync((int)(uintptr_t)(fh)) == 0)
{
return ERR_OK;
}
else
{
derror("flush file failed, err = %s", strerror(errno));
return ERR_FILE_OPERATION_FAILED;
}
}
struct posix_disk_aio_context : public disk_aio
{
struct aiocb cb;
aio_task* tsk;
native_posix_aio_provider* this_;
utils::notify_event* evt;
error_code err;
uint32_t bytes;
};
disk_aio* native_posix_aio_provider::prepare_aio_context(aio_task* tsk)
{
auto r = new posix_disk_aio_context;
bzero((char*)&r->cb, sizeof(r->cb));
r->tsk = tsk;
r->evt = nullptr;
return r;
}
void native_posix_aio_provider::aio(aio_task* aio_tsk)
{
aio_internal(aio_tsk, true);
}
void aio_completed(sigval sigval)
{
auto ctx = (posix_disk_aio_context *)sigval.sival_ptr;
if (dsn::tls_dsn.magic != 0xdeadbeef)
task::set_tls_dsn_context(ctx->tsk->node(), nullptr, nullptr);
int err = aio_error(&ctx->cb);
if (err != EINPROGRESS)
{
size_t bytes = aio_return(&ctx->cb); // from e.g., read or write
error_code ec;
if (err != 0)
{
derror("aio error, err = %s", strerror(err));
ec = ERR_FILE_OPERATION_FAILED;
}
else
{
ec = bytes > 0 ? ERR_OK : ERR_HANDLE_EOF;
}
if (!ctx->evt)
{
aio_task* aio(ctx->tsk);
ctx->this_->complete_io(aio, ec, bytes);
}
else
{
ctx->err = ec;
ctx->bytes = bytes;
ctx->evt->notify();
}
}
}
error_code native_posix_aio_provider::aio_internal(aio_task* aio_tsk, bool async, /*out*/ uint32_t* pbytes /*= nullptr*/)
{
auto aio = (posix_disk_aio_context *)aio_tsk->aio();
int r = 0;
aio->this_ = this;
memset(&aio->cb, 0, sizeof(aio->cb));
aio->cb.aio_reqprio = 0;
aio->cb.aio_lio_opcode = (aio->type == AIO_Read ? LIO_READ : LIO_WRITE);
aio->cb.aio_fildes = static_cast<int>((ssize_t)aio->file);
aio->cb.aio_buf = aio->buffer;
aio->cb.aio_nbytes = aio->buffer_size;
aio->cb.aio_offset = aio->file_offset;
// set up callback
aio->cb.aio_sigevent.sigev_notify = SIGEV_THREAD;
aio->cb.aio_sigevent.sigev_notify_function = aio_completed;
aio->cb.aio_sigevent.sigev_notify_attributes = nullptr;
aio->cb.aio_sigevent.sigev_value.sival_ptr = aio;
if (!async)
{
aio->evt = new utils::notify_event();
aio->err = ERR_OK;
aio->bytes = 0;
}
switch (aio->type)
{
case AIO_Read:
r = aio_read(&aio->cb);
break;
case AIO_Write:
r = aio_write(&aio->cb);
break;
default:
dassert (false, "unknown aio type %u", static_cast<int>(aio->type));
break;
}
if (r != 0)
{
derror("file op failed, err = %d (%s). On FreeBSD, you may need to load"
" aio kernel module by running 'sudo kldload aio'.", errno, strerror(errno));
if (async)
{
complete_io(aio_tsk, ERR_FILE_OPERATION_FAILED, 0);
}
else
{
delete aio->evt;
aio->evt = nullptr;
}
return ERR_FILE_OPERATION_FAILED;
}
else
{
if (async)
{
return ERR_IO_PENDING;
}
else
{
aio->evt->wait();
delete aio->evt;
aio->evt = nullptr;
if (pbytes != nullptr)
{
*pbytes = aio->bytes;
}
return aio->err;
}
}
}
}
} // end namespace dsn::tools
#endif

Просмотреть файл

@ -0,0 +1,72 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Microsoft Corporation
*
* -=- Robust Distributed System Nucleus (rDSN) -=-
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* Description:
* What is this file about?
*
* Revision history:
* xxxx-xx-xx, author, first version
* xxxx-xx-xx, author, fix bug about xxx
*/
#pragma once
# ifndef _WIN32
# include <dsn/tool_api.h>
# include <dsn/utility/synchronize.h>
# include <aio.h>
# include <fcntl.h>
namespace dsn {
namespace tools {
class native_posix_aio_provider : public aio_provider
{
public:
native_posix_aio_provider(disk_engine* disk, aio_provider* inner_provider);
~native_posix_aio_provider();
virtual dsn_handle_t open(const char* file_name, int flag, int pmode) override;
virtual error_code close(dsn_handle_t fh) override;
virtual error_code flush(dsn_handle_t fh) override;
virtual void aio(aio_task* aio) override;
virtual disk_aio* prepare_aio_context(aio_task* tsk) override;
virtual void start(io_modifer& ctx) override {}
protected:
error_code aio_internal(aio_task* aio, bool async, /*out*/ uint32_t* pbytes = nullptr);
private:
friend void aio_completed(sigval sigval);
};
}
}
# endif

Просмотреть файл

@ -0,0 +1,377 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Microsoft Corporation
*
* -=- Robust Distributed System Nucleus (rDSN) -=-
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* Description:
* What is this file about?
*
* Revision history:
* xxxx-xx-xx, author, first version
* xxxx-xx-xx, author, fix bug about xxx
*/
#ifdef _WIN32
#include "native_aio_provider.win.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
# ifdef __TITLE__
# undef __TITLE__
# endif
# define __TITLE__ "aio.provider.native"
namespace dsn { namespace tools {
native_win_aio_provider::native_win_aio_provider(disk_engine* disk, aio_provider* inner_provider)
: aio_provider(disk, inner_provider)
{
_iocp = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 0);
}
native_win_aio_provider::~native_win_aio_provider()
{
if (_worker_thr != nullptr && _iocp != NULL && _iocp != INVALID_HANDLE_VALUE)
{
::PostQueuedCompletionStatus(_iocp, 0, 1, NULL);
_worker_thr->join();
::CloseHandle(_iocp);
_iocp = INVALID_HANDLE_VALUE;
delete _worker_thr;
_worker_thr = nullptr;
}
}
void native_win_aio_provider::start(io_modifer& ctx)
{
_worker_thr = new std::thread([this, ctx]()
{
task::set_tls_dsn_context(node(), nullptr, ctx.queue);
const char* name = ::dsn::tools::get_service_node_name(node());
char buffer[128];
sprintf(buffer, "%s.aio", name);
task_worker::set_name(buffer);
worker();
});
::SetThreadPriority(_worker_thr->native_handle(), THREAD_PRIORITY_HIGHEST);
}
dsn_handle_t native_win_aio_provider::open(const char* file_name, int oflag, int pmode)
{
DWORD dwDesiredAccess = 0;
DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
DWORD dwCreationDisposition = 0;
DWORD dwFlagsAndAttributes = FILE_FLAG_OVERLAPPED;
SECURITY_ATTRIBUTES SecurityAttributes;
SecurityAttributes.nLength = sizeof(SecurityAttributes);
SecurityAttributes.lpSecurityDescriptor = NULL;
if (oflag & _O_NOINHERIT) {
SecurityAttributes.bInheritHandle = FALSE;
}
else {
SecurityAttributes.bInheritHandle = TRUE;
}
/*
* decode the access flags
*/
switch (oflag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {
case _O_RDONLY: /* read access */
dwDesiredAccess = GENERIC_READ;
break;
case _O_WRONLY: /* write access */
/* giving it read access as well
* because in append (a, not a+), we need
* to read the BOM to determine the encoding
* (ie. ANSI, UTF8, UTF16)
*/
if ((oflag & _O_APPEND)
&& (oflag & (_O_WTEXT | _O_U16TEXT | _O_U8TEXT)) != 0)
{
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
}
else
{
dwDesiredAccess = GENERIC_WRITE;
}
break;
case _O_RDWR: /* read and write access */
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
break;
default: /* error, bad oflag */
_doserrno = 0L; /* not an OS error */
derror("Invalid open flag\n");
}
/*
* decode open/create method flags
*/
switch (oflag & (_O_CREAT | _O_EXCL | _O_TRUNC)) {
case 0:
case _O_EXCL: // ignore EXCL w/o CREAT
dwCreationDisposition = OPEN_EXISTING;
break;
case _O_CREAT:
dwCreationDisposition = OPEN_ALWAYS;
break;
case _O_CREAT | _O_EXCL:
case _O_CREAT | _O_TRUNC | _O_EXCL:
dwCreationDisposition = CREATE_NEW;
break;
case _O_TRUNC:
case _O_TRUNC | _O_EXCL: // ignore EXCL w/o CREAT
dwCreationDisposition = TRUNCATE_EXISTING;
break;
case _O_CREAT | _O_TRUNC:
dwCreationDisposition = CREATE_ALWAYS;
break;
default:
// this can't happen ... all cases are covered
_doserrno = 0L;
derror("Invalid open flag");
}
/*
* try to open/create the file
*/
HANDLE fileHandle = ::CreateFileA(file_name,
dwDesiredAccess,
dwShareMode,
&SecurityAttributes,
dwCreationDisposition,
dwFlagsAndAttributes,
0);
if (fileHandle != INVALID_HANDLE_VALUE && fileHandle != nullptr)
{
if (_iocp != ::CreateIoCompletionPort(fileHandle, _iocp, 0, 0))
{
dassert(false, "cannot associate file handle %s to io completion port, err = 0x%x\n", file_name, ::GetLastError());
return 0;
}
else
{
return (dsn_handle_t)(fileHandle);
}
}
else
{
derror("cannot create file %s, err = 0x%x\n", file_name, ::GetLastError());
return 0;
}
}
error_code native_win_aio_provider::close(dsn_handle_t fh)
{
if (fh == DSN_INVALID_FILE_HANDLE || ::CloseHandle((HANDLE)(fh)))
{
return ERR_OK;
}
else
{
derror("close file failed, err = 0x%x\n", ::GetLastError());
return ERR_FILE_OPERATION_FAILED;
}
}
error_code native_win_aio_provider::flush(dsn_handle_t fh)
{
if (fh == DSN_INVALID_FILE_HANDLE || ::FlushFileBuffers((HANDLE)(fh)))
{
return ERR_OK;
}
else
{
derror("close file failed, err = 0x%x\n", ::GetLastError());
return ERR_FILE_OPERATION_FAILED;
}
}
struct windows_disk_aio_context : public disk_aio
{
OVERLAPPED olp;
aio_task* tsk;
utils::notify_event* evt;
error_code err;
uint32_t bytes;
};
disk_aio* native_win_aio_provider::prepare_aio_context(aio_task* tsk)
{
auto r = new windows_disk_aio_context;
ZeroMemory(&r->olp, sizeof(r->olp));
r->tsk = tsk;
r->evt = nullptr;
return r;
}
void native_win_aio_provider::aio(aio_task* aio_tsk)
{
auto err = aio_internal(aio_tsk, true);
err.end_tracking();
}
error_code native_win_aio_provider::aio_internal(aio_task* aio_tsk, bool async, /*out*/ uint32_t* pbytes /*= nullptr*/)
{
auto aio = (windows_disk_aio_context*)aio_tsk->aio();
BOOL r = FALSE;
aio->olp.Offset = (uint32_t)aio->file_offset;
aio->olp.OffsetHigh = (uint32_t)(aio->file_offset >> 32);
if (!async)
{
aio->evt = new utils::notify_event();
aio->err = ERR_OK;
aio->bytes = 0;
}
switch (aio->type)
{
case AIO_Read:
r = ::ReadFile((HANDLE)aio->file, aio->buffer, aio->buffer_size, NULL, &aio->olp);
break;
case AIO_Write:
r = ::WriteFile((HANDLE)aio->file, aio->buffer, aio->buffer_size, NULL, &aio->olp);
break;
default:
dassert (false, "unknown aio type %u", static_cast<int>(aio->type));
break;
}
if (!r)
{
int dwErrorCode = ::GetLastError();
if (dwErrorCode != ERROR_IO_PENDING)
{
derror("file operation failed, err = %u", dwErrorCode);
error_code err = dwErrorCode == ERROR_SUCCESS ? ERR_OK :
(dwErrorCode == ERROR_HANDLE_EOF ? ERR_HANDLE_EOF : ERR_FILE_OPERATION_FAILED);
if (async)
{
complete_io(aio_tsk, err, 0);
}
else
{
delete aio->evt;
aio->evt = nullptr;
}
return err;
}
}
if (async)
{
return ERR_IO_PENDING;
}
else
{
aio->evt->wait();
delete aio->evt;
aio->evt = nullptr;
*pbytes = aio->bytes;
return aio->err;
}
}
void native_win_aio_provider::worker()
{
DWORD dwTransLen;
DWORD dwErrorCode;
ULONG_PTR dwKey;
LPOVERLAPPED overLap;
do
{
bool ret = (0 != GetQueuedCompletionStatus(_iocp, &dwTransLen, &dwKey, &overLap, INFINITE));
if (dwKey) break;
if (ret)
{
windows_disk_aio_context* ctx = CONTAINING_RECORD(overLap, windows_disk_aio_context, olp);
if (!ctx->evt)
{
aio_task* aio(ctx->tsk);
complete_io(aio, ERR_OK, dwTransLen);
}
else
{
ctx->err = ERR_OK;
ctx->bytes = dwTransLen;
ctx->evt->notify();
}
}
else if (overLap)
{
dwErrorCode = ::GetLastError();
dinfo("file operation failed, err = %u", dwErrorCode);
windows_disk_aio_context* ctx = CONTAINING_RECORD(overLap, windows_disk_aio_context, olp);
error_code err = dwErrorCode == ERROR_SUCCESS ? ERR_OK :
(dwErrorCode == ERROR_HANDLE_EOF ? ERR_HANDLE_EOF : ERR_FILE_OPERATION_FAILED);
if (!ctx->evt)
{
aio_task* aio(ctx->tsk);
complete_io(aio, err, dwTransLen);
}
else
{
ctx->err = err;
ctx->bytes = dwTransLen;
ctx->evt->notify();
}
}
else
{
::Sleep(1);
}
} while (true);
}
}} // end namespace dsn::tools
#endif

Просмотреть файл

@ -0,0 +1,70 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Microsoft Corporation
*
* -=- Robust Distributed System Nucleus (rDSN) -=-
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* Description:
* What is this file about?
*
* Revision history:
* xxxx-xx-xx, author, first version
* xxxx-xx-xx, author, fix bug about xxx
*/
#pragma once
# ifdef _WIN32
# include <dsn/tool_api.h>
# include <dsn/utility/synchronize.h>
namespace dsn {
namespace tools {
class native_win_aio_provider : public aio_provider
{
public:
native_win_aio_provider(disk_engine* disk, aio_provider* inner_provider);
~native_win_aio_provider();
virtual dsn_handle_t open(const char* file_name, int flag, int pmode);
virtual error_code close(dsn_handle_t fh);
virtual error_code flush(dsn_handle_t fh);
virtual void aio(aio_task* aio);
virtual disk_aio* prepare_aio_context(aio_task* tsk);
virtual void start(io_modifer& ctx) override;
protected:
error_code aio_internal(aio_task* aio, bool async, /*out*/ uint32_t* pbytes = nullptr);
private:
void worker();
std::thread *_worker_thr;
HANDLE _iocp;
};
}
}
# endif

Просмотреть файл

@ -94,7 +94,7 @@ namespace dsn { namespace tools {
sim_network_provider* rnet = nullptr;
if (!s_switch[task_spec::get(msg->local_rpc_code)->rpc_call_channel][msg->hdr_format].get(remote_address(), rnet))
{
derror("cannot find destination node %s in simulator",
derror("cannot find destination node %s in emulator",
remote_address().to_string()
);
//on_disconnected(); // disable this to avoid endless resending
@ -167,10 +167,10 @@ namespace dsn { namespace tools {
_min_message_delay_microseconds = 1;
_max_message_delay_microseconds = 100000;
_min_message_delay_microseconds = (uint32_t)dsn_config_get_value_uint64("tools.simulator",
_min_message_delay_microseconds = (uint32_t)dsn_config_get_value_uint64("tools.emulator",
"min_message_delay_microseconds", _min_message_delay_microseconds,
"min message delay (us)");
_max_message_delay_microseconds = (uint32_t)dsn_config_get_value_uint64("tools.simulator",
_max_message_delay_microseconds = (uint32_t)dsn_config_get_value_uint64("tools.emulator",
"max_message_delay_microseconds", _max_message_delay_microseconds,
"max message delay (us)");
}

Просмотреть файл

@ -33,7 +33,7 @@
* xxxx-xx-xx, author, fix bug about xxx
*/
# include "simulator.h"
# include "emulator.h"
# include <dsn/service_api_c.h>
# include <dsn/tool-api/node_scoper.h>
# include "scheduler.h"
@ -43,7 +43,7 @@
# ifdef __TITLE__
# undef __TITLE__
# endif
# define __TITLE__ "simulator"
# define __TITLE__ "emulator"
namespace dsn { namespace tools {
@ -115,13 +115,13 @@ scheduler::scheduler(void)
_time_ns = 0;
_running = false;
_running_thread = nullptr;
task_worker::on_create.put_back(on_task_worker_create, "simulation.on_task_worker_create");
task_worker::on_start.put_back(on_task_worker_start, "simulation.on_task_worker_start");
task_worker::on_create.put_back(on_task_worker_create, "emulation.on_task_worker_create");
task_worker::on_start.put_back(on_task_worker_start, "emulation.on_task_worker_start");
for (int i = 0; i <= dsn_task_code_max(); i++)
{
task_spec::get(i)->on_task_wait_pre.put_back(scheduler::on_task_wait, "simulation.on_task_wait");
task_spec::get(i)->on_task_wait_notified.put_back(scheduler::on_task_wait_notified, "simulation.on_task_wait_notified");
task_spec::get(i)->on_task_wait_pre.put_back(scheduler::on_task_wait, "emulation.on_task_wait");
task_spec::get(i)->on_task_wait_notified.put_back(scheduler::on_task_wait_notified, "emulation.on_task_wait_notified");
}
task_ext::register_ext(task_state_ext::deletor);

Просмотреть файл

@ -72,7 +72,7 @@ void sim_task_queue::enqueue(task* t)
}
}
// we always return 1 or 0 task in simulator
// we always return 1 or 0 task in emulator
task* sim_task_queue::dequeue(/*inout*/int& batch_size)
{
scheduler::instance().wait_schedule(false);

Просмотреть файл

@ -0,0 +1 @@
test.config.tools.emulator.ini

Просмотреть файл

@ -0,0 +1,147 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
[apps..default]
run = true
count = 1
network.client.RPC_CHANNEL_TCP = dsn::tools::asio_network_provider, 65536
network.client.RPC_CHANNEL_UDP = dsn::tools::asio_udp_provider, 65536
network.server.0.RPC_CHANNEL_TCP = dsn::tools::asio_network_provider, 65536
network.server.0.RPC_CHANNEL_UDP = dsn::tools::asio_udp_provider, 65536
[apps.client]
type = test
arguments = localhost 20101
run = true
ports = 20001
count = 1
delay_seconds = 1
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER, THREAD_POOL_FOR_TEST_1, THREAD_POOL_FOR_TEST_2
[apps.server]
type = test
arguments =
ports = 20101,20102
run = true
count = 1
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER
network.client.RPC_CHANNEL_TCP = dsn::tools::asio_network_provider,65536
network.server.20101.RPC_CHANNEL_TCP = dsn::tools::asio_network_provider,65536
network.server.20102.RPC_CHANNEL_TCP = dsn::tools::asio_network_provider,65536
network.server.20103.RPC_CHANNEL_TCP = dsn::tools::asio_network_provider,65536
[apps.server_group]
type = test
arguments =
ports = 20201
run = true
count = 3
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER
[apps.server_not_run]
type = test
arguments =
ports = 20301
run = false
count = 1
pools = THREAD_POOL_DEFAULT, THREAD_POOL_TEST_SERVER
[core]
tool = emulator
;tool = nativerun
;tool = fastrun
toollets = tracer, profiler
pause_on_start = false
cli_local = true
cli_remote = true
logging_start_level = LOG_LEVEL_INFORMATION
logging_factory_name = dsn::tools::simple_logger
io_worker_count = 1
start_nfs = false
gtest = true
gtest_arguments = --gtest_filter=tools_emulator.*
[tools.simple_logger]
fast_flush = true
short_header = false
stderr_start_level = LOG_LEVEL_FATAL
[tools.emulator]
random_seed = 0
[network]
; how many network threads for network library (used by asio)
io_service_worker_count = 2
[task..default]
is_trace = true
is_profile = true
allow_inline = false
rpc_call_channel = RPC_CHANNEL_TCP
rpc_message_header_format = dsn
rpc_timeout_milliseconds = 1000
[task.LPC_AIO_IMMEDIATE_CALLBACK]
is_trace = false
is_profile = false
allow_inline = false
[task.LPC_RPC_TIMEOUT]
is_trace = false
is_profile = false
[task.RPC_TEST_UDP]
rpc_call_channel = RPC_CHANNEL_UDP
rpc_message_crc_required = true
; specification for each thread pool
[threadpool..default]
worker_count = 2
[threadpool.THREAD_POOL_DEFAULT]
partitioned = false
; max_input_queue_length = 1024
worker_priority = THREAD_xPRIORITY_NORMAL
[threadpool.THREAD_POOL_TEST_SERVER]
partitioned = false
admission_controller_factory_name = dsn::tools::admission_controller_for_test
[threadpool.THREAD_POOL_FOR_TEST_1]
worker_count = 2
worker_priority = THREAD_xPRIORITY_HIGHEST
worker_share_core = false
worker_affinity_mask = 1
max_input_queue_length = 1024
partitioned = false
admission_controller_factory_name = dsn::tools::admission_controller_for_test
admission_controller_arguments = this is test argument
[threadpool.THREAD_POOL_FOR_TEST_2]
worker_count = 2
worker_priority = THREAD_xPRIORITY_NORMAL
worker_share_core = true
worker_affinity_mask = 1
max_input_queue_length = 1024
partitioned = true
[components.simple_perf_counter]
counter_computation_interval_seconds = 1
[components.simple_perf_counter_v2_atomic]
counter_computation_interval_seconds = 1
[components.simple_perf_counter_v2_fast]
counter_computation_interval_seconds = 1
[core.test]
count = 1
run = true

@ -1 +1 @@
Subproject commit 0bb299564ad19f63d315d797e96d1048ebbe4cc5
Subproject commit ee09c5f2c237d940e6edc2674b4c09cec7fbd117

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
@ -19,14 +20,14 @@ pools = THREAD_POOL_DEFAULT
[core]
;tool = simulator
;tool = emulator
tool = nativerun
;toollets = tracer, profiler
;fault_injector
pause_on_start = false
cli_local = false
[tools.simulator]
[tools.emulator]
random_seed = 2756568580
use_given_random_seed = true

Просмотреть файл

@ -1,5 +1,6 @@
[modules]
dsn.tools.common
dsn.tools.emulator
dsn.tools.nfs
dsn.dist.uri.resolver
@ -12,14 +13,14 @@ count = 1
[core]
;tool = simulator
;tool = emulator
tool = nativerun
;toollets = tracer, profiler
;fault_injector
pause_on_start = false
cli_local = false
[tools.simulator]
[tools.emulator]
random_seed = 2756568580
[network]