2012-01-19 16:49:54 +00:00
|
|
|
/*
|
|
|
|
* newserver.cpp
|
|
|
|
*
|
|
|
|
* Copyright 2010-2012 Yahoo! Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* Created on: Aug 11, 2010
|
|
|
|
* Author: sears
|
|
|
|
*/
|
2010-08-11 22:46:55 +00:00
|
|
|
#include <stasis/transactional.h>
|
2011-04-20 20:17:26 +00:00
|
|
|
#include <stasis/logger/safeWrites.h>
|
2010-08-11 22:46:55 +00:00
|
|
|
|
2011-01-25 02:07:16 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
|
2010-08-11 22:46:55 +00:00
|
|
|
#include "merger.h"
|
2012-02-22 23:12:28 +00:00
|
|
|
#include "blsm.h"
|
2010-08-11 22:46:55 +00:00
|
|
|
#include "simpleServer.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2011-01-25 02:07:16 +00:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2010-08-11 22:46:55 +00:00
|
|
|
int64_t c0_size = 1024 * 1024 * 512 * 1;
|
2011-04-20 21:51:04 +00:00
|
|
|
int log_mode = 0; // do not log by default.
|
2011-04-28 21:56:25 +00:00
|
|
|
int64_t expiry_delta = 0; // do not gc by default
|
2011-06-09 00:07:42 +00:00
|
|
|
int port = simpleServer::DEFAULT_PORT;
|
2011-01-11 19:24:16 +00:00
|
|
|
stasis_buffer_manager_size = 1 * 1024 * 1024 * 1024 / PAGE_SIZE; // 1.5GB total
|
2010-08-11 22:46:55 +00:00
|
|
|
|
2011-04-20 21:51:04 +00:00
|
|
|
for(int i = 1; i < argc; i++) {
|
|
|
|
if(!strcmp(argv[i], "--test")) {
|
|
|
|
stasis_buffer_manager_size = 3 * 1024 * 1024 * 128 / PAGE_SIZE; // 228MB total
|
|
|
|
c0_size = 1024 * 1024 * 100;
|
|
|
|
printf("warning: running w/ tiny c0 for testing\n"); // XXX build a separate test server and deployment server?
|
|
|
|
} else if(!strcmp(argv[i], "--benchmark")) {
|
2011-04-23 18:53:38 +00:00
|
|
|
stasis_buffer_manager_size = (1024LL * 1024LL * 1024LL * 2LL) / PAGE_SIZE; // 4GB total
|
|
|
|
c0_size = 1024LL * 1024LL * 1024LL * 2LL;
|
2011-04-20 21:51:04 +00:00
|
|
|
printf("note: running w/ 2GB c0 for benchmarking\n"); // XXX build a separate test server and deployment server?
|
|
|
|
} else if(!strcmp(argv[i], "--log-mode")) {
|
|
|
|
i++;
|
|
|
|
log_mode = atoi(argv[i]);
|
2011-04-28 21:56:25 +00:00
|
|
|
} else if(!strcmp(argv[i], "--expiry-delta")) {
|
|
|
|
i++;
|
|
|
|
expiry_delta = atoi(argv[i]);
|
2011-06-09 00:07:42 +00:00
|
|
|
} else if(!strcmp(argv[i], "--port")) {
|
|
|
|
i++;
|
|
|
|
port = atoi(argv[i]);
|
2011-04-20 21:51:04 +00:00
|
|
|
} else {
|
2011-06-09 00:07:42 +00:00
|
|
|
fprintf(stderr, "Usage: %s [--test|--benchmark] [--log-mode <int>] [--expiry-delta <int>] [--port <int>]", argv[0]);
|
2011-04-20 21:51:04 +00:00
|
|
|
abort();
|
|
|
|
}
|
2010-08-11 22:46:55 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 22:57:02 +00:00
|
|
|
blsm::init_stasis();
|
2011-01-11 19:24:16 +00:00
|
|
|
|
|
|
|
int xid = Tbegin();
|
|
|
|
|
|
|
|
|
|
|
|
recordid table_root = ROOT_RECORD;
|
2011-04-21 00:28:05 +00:00
|
|
|
{
|
2012-02-22 22:57:02 +00:00
|
|
|
blsm ltable(log_mode, c0_size);
|
2011-04-28 21:56:25 +00:00
|
|
|
ltable.expiry = expiry_delta;
|
2011-04-21 00:28:05 +00:00
|
|
|
|
|
|
|
if(TrecordType(xid, ROOT_RECORD) == INVALID_SLOT) {
|
|
|
|
printf("Creating empty logstore\n");
|
|
|
|
table_root = ltable.allocTable(xid);
|
|
|
|
assert(table_root.page == ROOT_RECORD.page &&
|
|
|
|
table_root.slot == ROOT_RECORD.slot);
|
|
|
|
} else {
|
|
|
|
printf("Opened existing logstore\n");
|
|
|
|
table_root.size = TrecordSize(xid, ROOT_RECORD);
|
|
|
|
ltable.openTable(xid, table_root);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
merge_scheduler * mscheduler = new merge_scheduler(<able);
|
|
|
|
mscheduler->start();
|
|
|
|
ltable.replayLog();
|
|
|
|
|
2011-06-09 00:07:42 +00:00
|
|
|
simpleServer *lserver = new simpleServer(<able, simpleServer::DEFAULT_THREADS, port);
|
2011-04-21 00:28:05 +00:00
|
|
|
|
|
|
|
lserver->acceptLoop();
|
|
|
|
|
|
|
|
printf ("Stopping server...\n");
|
|
|
|
delete lserver;
|
|
|
|
|
|
|
|
printf("Stopping merge threads...\n");
|
|
|
|
mscheduler->shutdown();
|
|
|
|
delete mscheduler;
|
|
|
|
|
|
|
|
printf("Deinitializing stasis...\n");
|
|
|
|
fflush(stdout);
|
2010-08-11 22:46:55 +00:00
|
|
|
}
|
2012-02-22 22:57:02 +00:00
|
|
|
blsm::deinit_stasis();
|
2010-08-11 22:46:55 +00:00
|
|
|
|
|
|
|
printf("Shutdown complete\n");
|
|
|
|
}
|