use of org.apache.bookkeeper.common.component.LifecycleComponent in project bookkeeper by apache.
the class Main method doMain.
static int doMain(String[] args) {
ServerConfiguration conf;
// 0. parse command line
try {
conf = parseCommandLine(args);
} catch (IllegalArgumentException iae) {
return ExitCode.INVALID_CONF;
}
// 1. building the component stack:
LifecycleComponent server;
try {
server = buildBookieServer(new BookieConfiguration(conf));
} catch (Exception e) {
log.error("Failed to build bookie server", e);
return ExitCode.SERVER_EXCEPTION;
}
// 2. start the server
try {
ComponentStarter.startComponent(server).get();
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
// the server is interrupted
log.info("Bookie server is interrupted. Exiting ...");
} catch (ExecutionException ee) {
log.error("Error in bookie shutdown", ee.getCause());
return ExitCode.SERVER_EXCEPTION;
}
return ExitCode.OK;
}
use of org.apache.bookkeeper.common.component.LifecycleComponent in project bookkeeper by apache.
the class StreamCluster method startServer.
private LifecycleComponent startServer() throws Exception {
int bookiePort;
int grpcPort;
boolean success = false;
int retries = 0;
while (!success) {
synchronized (this) {
bookiePort = nextBookiePort++;
grpcPort = nextGrpcPort++;
}
LifecycleComponent server = null;
try {
ServerConfiguration serverConf = new ServerConfiguration();
serverConf.loadConf(baseConf);
serverConf.setBookiePort(bookiePort);
File bkDir = new File(spec.storageRootDir(), "bookie_" + bookiePort);
serverConf.setJournalDirName(bkDir.getPath());
serverConf.setLedgerDirNames(new String[] { bkDir.getPath() });
DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
dlConf.loadConf(serverConf);
File rangesStoreDir = new File(spec.storageRootDir(), "ranges_" + grpcPort);
StorageConfiguration storageConf = new StorageConfiguration(serverConf);
storageConf.setRangeStoreDirNames(new String[] { rangesStoreDir.getPath() });
storageConf.setServeReadOnlyTables(spec.serveReadOnlyTable);
log.info("Attempting to start storage server at (bookie port = {}, grpc port = {})" + " : bkDir = {}, rangesStoreDir = {}, serveReadOnlyTables = {}", bookiePort, grpcPort, bkDir, rangesStoreDir, spec.serveReadOnlyTable);
server = StorageServer.startStorageServer(serverConf, grpcPort, spec.numServers() * 2, Optional.empty());
server.start();
log.info("Started storage server at (bookie port = {}, grpc port = {})", bookiePort, grpcPort);
this.rpcEndpoints.add(StorageServer.createLocalEndpoint(grpcPort, false));
return server;
} catch (Throwable e) {
log.error("Failed to start storage server", e);
if (null != server) {
server.stop();
}
if (e.getCause() instanceof BindException) {
retries++;
if (retries > MAX_RETRIES) {
throw (BindException) e.getCause();
}
} else {
throw e;
}
}
}
throw new IOException("Failed to start any storage server.");
}
use of org.apache.bookkeeper.common.component.LifecycleComponent in project bookkeeper by apache.
the class StorageServer method startStorageServer.
public static LifecycleComponent startStorageServer(CompositeConfiguration conf, int grpcPort, int numStorageContainers, Optional<String> instanceName) throws ConfigurationException, UnknownHostException {
BookieConfiguration bkConf = BookieConfiguration.of(conf);
bkConf.validate();
DLConfiguration dlConf = DLConfiguration.of(conf);
dlConf.validate();
StorageServerConfiguration serverConf = StorageServerConfiguration.of(conf);
serverConf.validate();
StorageConfiguration storageConf = new StorageConfiguration(conf);
storageConf.validate();
// Get my local endpoint
Endpoint myEndpoint = createLocalEndpoint(grpcPort, false);
// Create shared resources
StorageResources storageResources = StorageResources.create();
// Create the stats provider
StatsProviderService statsProviderService = new StatsProviderService(bkConf);
StatsLogger rootStatsLogger = statsProviderService.getStatsProvider().getStatsLogger("");
// Create the bookie service
BookieService bookieService = new BookieService(bkConf, rootStatsLogger);
// Create the distributedlog namespace service
DLNamespaceProviderService dlNamespaceProvider = new DLNamespaceProviderService(bookieService.serverConf(), dlConf, rootStatsLogger.scope("dl"));
// Create range (stream) store
RangeStoreBuilder rangeStoreBuilder = RangeStoreBuilder.newBuilder().withStatsLogger(rootStatsLogger.scope("storage")).withStorageConfiguration(storageConf).withStorageResources(storageResources).withNumStorageContainers(numStorageContainers).withDefaultBackendUri(dlNamespaceProvider.getDlogUri()).withStorageContainerManagerFactory((ignored, storeConf, registry) -> new HelixStorageContainerManager(bookieService.serverConf().getZkServers(), "stream/helix", storeConf, registry, myEndpoint, instanceName, rootStatsLogger.scope("helix"))).withRangeStoreFactory(new MVCCStoreFactoryImpl(dlNamespaceProvider, storageConf.getRangeStoreDirs(), storageResources, storageConf.getServeReadOnlyTables()));
StorageService storageService = new StorageService(storageConf, rangeStoreBuilder, rootStatsLogger.scope("storage"));
// Create gRPC server
StatsLogger rpcStatsLogger = rootStatsLogger.scope("grpc");
GrpcServerSpec serverSpec = GrpcServerSpec.builder().storeSupplier(storageService).storeServerConf(serverConf).endpoint(myEndpoint).statsLogger(rpcStatsLogger).build();
GrpcService grpcService = new GrpcService(serverConf, serverSpec, rpcStatsLogger);
// Create all the service stack
return LifecycleComponentStack.newBuilder().withName("storage-server").addComponent(// stats provider
statsProviderService).addComponent(// bookie server
bookieService).addComponent(// service that provides dl namespace
dlNamespaceProvider).addComponent(// range (stream) store
storageService).addComponent(// range (stream) server (gRPC)
grpcService).build();
}
use of org.apache.bookkeeper.common.component.LifecycleComponent in project bookkeeper by apache.
the class StreamCluster method startServers.
private void startServers() throws Exception {
log.info("Starting {} storage servers.", spec.numServers());
ExecutorService executor = Executors.newCachedThreadPool();
List<Future<LifecycleComponent>> startFutures = Lists.newArrayList();
for (int i = 0; i < spec.numServers(); i++) {
Future<LifecycleComponent> future = executor.submit(() -> startServer());
startFutures.add(future);
}
for (Future<LifecycleComponent> future : startFutures) {
servers.add(future.get());
}
log.info("Started {} storage servers.", spec.numServers());
executor.shutdown();
}
use of org.apache.bookkeeper.common.component.LifecycleComponent in project bookkeeper by apache.
the class StorageServer method doMain.
static int doMain(String[] args) {
// register thread uncaught exception handler
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> log.error("Uncaught exception in thread {}: {}", thread.getName(), exception.getMessage()));
// parse the commandline
ServerArguments arguments = new ServerArguments();
JCommander jCommander = new JCommander(arguments);
jCommander.setProgramName("StorageServer");
jCommander.parse(args);
if (arguments.help) {
jCommander.usage();
return ExitCode.INVALID_CONF.code();
}
CompositeConfiguration conf = new CompositeConfiguration();
if (null != arguments.serverConfigFile) {
loadConfFile(conf, arguments.serverConfigFile);
}
int grpcPort = arguments.port;
LifecycleComponent storageServer;
try {
storageServer = startStorageServer(conf, grpcPort, 1024, Optional.empty());
} catch (ConfigurationException e) {
log.error("Invalid storage configuration", e);
return ExitCode.INVALID_CONF.code();
} catch (UnknownHostException e) {
log.error("Unknonw host name", e);
return ExitCode.UNKNOWN_HOSTNAME.code();
}
CompletableFuture<Void> liveFuture = ComponentStarter.startComponent(storageServer);
try {
liveFuture.get();
} catch (InterruptedException e) {
// the server is interrupted.
Thread.currentThread().interrupt();
log.info("Storage server is interrupted. Exiting ...");
} catch (ExecutionException e) {
log.info("Storage server is exiting ...");
}
return ExitCode.OK.code();
}
Aggregations