|
@ -65,6 +65,20 @@ int main( |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
size_t db_port = 20450; |
|
|
|
|
|
|
|
|
|
|
|
if(cmd_args.isFlagSet("-port")) |
|
|
|
|
|
{ |
|
|
|
|
|
try{ |
|
|
|
|
|
db_port = std::stoi(cmd_args.getFlagValue("-port")); |
|
|
|
|
|
if(db_port>std::numeric_limits<uint16_t>::max()) throw std::runtime_error("invalid_port"); |
|
|
|
|
|
} catch (...) { |
|
|
|
|
|
std::cerr << "Invalid port value" << std::endl; |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#ifdef UNITTEST
|
|
|
#ifdef UNITTEST
|
|
|
{ |
|
|
{ |
|
|
database db(database::create(utest_str, utest_size*2)); |
|
|
database db(database::create(utest_str, utest_size*2)); |
|
@ -163,7 +177,7 @@ int main( |
|
|
auto soc = socket(AF_INET, SOCK_DGRAM, 0); |
|
|
auto soc = socket(AF_INET, SOCK_DGRAM, 0); |
|
|
struct sockaddr_in addr; |
|
|
struct sockaddr_in addr; |
|
|
addr.sin_family = AF_INET; |
|
|
addr.sin_family = AF_INET; |
|
|
addr.sin_port = htons(mi">20450); |
|
|
|
|
|
|
|
|
addr.sin_port = htons(n">db_port); |
|
|
memset((void*)&addr.sin_addr, 0, sizeof(addr.sin_addr)); |
|
|
memset((void*)&addr.sin_addr, 0, sizeof(addr.sin_addr)); |
|
|
bind(soc,(struct sockaddr*)&addr,sizeof(addr)); |
|
|
bind(soc,(struct sockaddr*)&addr,sizeof(addr)); |
|
|
|
|
|
|
|
@ -227,6 +241,29 @@ int main( |
|
|
reply_size = sizeof(reply.rep_id) + sizeof(reply.identifier); |
|
|
reply_size = sizeof(reply.rep_id) + sizeof(reply.identifier); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
|
|
|
case db_op::stats: |
|
|
|
|
|
{ |
|
|
|
|
|
reply.rep_id = recv.rep_id; |
|
|
|
|
|
auto stats = (stats_data*)&reply.page; |
|
|
|
|
|
stats->total_pages = (*run_db.metadata).page_cnt; |
|
|
|
|
|
stats->total_records = (*run_db.metadata).record_cnt; |
|
|
|
|
|
stats->free_deleted = (*run_db.metadata).last_delete; |
|
|
|
|
|
stats->free = |
|
|
|
|
|
(*run_db.metadata).last_delete |
|
|
|
|
|
+ (*run_db.metadata).page_cnt |
|
|
|
|
|
- (*run_db.metadata).last_page; |
|
|
|
|
|
uint64_t cow_full = 0; |
|
|
|
|
|
for(auto& elem : run_db.records) |
|
|
|
|
|
{ |
|
|
|
|
|
if(elem.second.timestamp == std::numeric_limits<uint64_t>::max()) |
|
|
|
|
|
{ |
|
|
|
|
|
++cow_full; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
stats->cow_full = cow_full; |
|
|
|
|
|
reply_size = sizeof(reply); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
default: |
|
|
default: |
|
|
std::cerr << "bad_request " << (uint32_t)static_cast<db_op>(recv.op) << std::endl; |
|
|
std::cerr << "bad_request " << (uint32_t)static_cast<db_op>(recv.op) << std::endl; |
|
|
continue; |
|
|
continue; |
|
|