Search in sources :

Example 1 with FileWriterManager

use of com.bonree.brfs.disknode.data.write.FileWriterManager in project BRFS by zhangnianli.

the class EmptyMain method start.

@Override
public void start() throws Exception {
    LOG.info("Empty Main--port[{}]", httpConfig.getPort());
    createRootDirIfNeeded(diskContext.getRootDir());
    RecordCollectionManager recorderManager = new RecordCollectionManager();
    writerManager = new FileWriterManager(recorderManager);
    writerManager.start();
    writerManager.rebuildFileWriterbyDir(diskContext.getRootDir());
    server = new NettyHttpServer(httpConfig);
    requestHandlerExecutor = Executors.newFixedThreadPool(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_REQUEST_HANDLER_NUM), new PooledThreadFactory("request_handler"));
    FileFormater fileFormater = new SimpleFileFormater(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_MAX_CAPACITY));
    NettyHttpRequestHandler requestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
    requestHandler.addMessageHandler("PUT", new OpenMessageHandler(diskContext, writerManager));
    requestHandler.addMessageHandler("POST", new WriteMessageHandler(diskContext, writerManager, fileFormater));
    requestHandler.addMessageHandler("GET", new ReadMessageHandler(diskContext, fileFormater));
    requestHandler.addMessageHandler("CLOSE", new CloseMessageHandler(diskContext, writerManager, fileFormater));
    requestHandler.addMessageHandler("DELETE", new DeleteMessageHandler(diskContext, writerManager));
    server.addContextHandler(DiskContext.URI_DISK_NODE_ROOT, requestHandler);
    NettyHttpRequestHandler flushRequestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
    flushRequestHandler.addMessageHandler("POST", new FlushMessageHandler(diskContext, writerManager));
    server.addContextHandler(DiskContext.URI_FLUSH_NODE_ROOT, flushRequestHandler);
    NettyHttpRequestHandler sequenceRequestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
    sequenceRequestHandler.addMessageHandler("GET", new FileLengthMessageHandler(diskContext, writerManager, fileFormater));
    server.addContextHandler(DiskContext.URI_LENGTH_NODE_ROOT, sequenceRequestHandler);
    NettyHttpRequestHandler listRequestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
    listRequestHandler.addMessageHandler("GET", new ListMessageHandler(diskContext));
    server.addContextHandler(DiskContext.URI_LIST_NODE_ROOT, listRequestHandler);
    NettyHttpRequestHandler recoverRequestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
    recoverRequestHandler.addMessageHandler("POST", new RecoveryMessageHandler(diskContext, serviceManager, writerManager, fileFormater));
    server.addContextHandler(DiskContext.URI_RECOVER_NODE_ROOT, recoverRequestHandler);
    NettyHttpRequestHandler pingRequestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
    pingRequestHandler.addMessageHandler("GET", new PingPongRequestHandler());
    server.addContextHandler(DiskContext.URI_PING_PONG_ROOT, pingRequestHandler);
    server.start();
}
Also used : RecordCollectionManager(com.bonree.brfs.disknode.data.write.record.RecordCollectionManager) RecoveryMessageHandler(com.bonree.brfs.disknode.server.handler.RecoveryMessageHandler) PooledThreadFactory(com.bonree.brfs.common.utils.PooledThreadFactory) PingPongRequestHandler(com.bonree.brfs.disknode.server.handler.PingPongRequestHandler) FileWriterManager(com.bonree.brfs.disknode.data.write.FileWriterManager) NettyHttpServer(com.bonree.brfs.common.net.http.netty.NettyHttpServer) FlushMessageHandler(com.bonree.brfs.disknode.server.handler.FlushMessageHandler) CloseMessageHandler(com.bonree.brfs.disknode.server.handler.CloseMessageHandler) FileLengthMessageHandler(com.bonree.brfs.disknode.server.handler.FileLengthMessageHandler) ListMessageHandler(com.bonree.brfs.disknode.server.handler.ListMessageHandler) NettyHttpRequestHandler(com.bonree.brfs.common.net.http.netty.NettyHttpRequestHandler) FileFormater(com.bonree.brfs.disknode.fileformat.FileFormater) SimpleFileFormater(com.bonree.brfs.disknode.fileformat.impl.SimpleFileFormater) ReadMessageHandler(com.bonree.brfs.disknode.server.handler.ReadMessageHandler) DeleteMessageHandler(com.bonree.brfs.disknode.server.handler.DeleteMessageHandler) WriteMessageHandler(com.bonree.brfs.disknode.server.handler.WriteMessageHandler) SimpleFileFormater(com.bonree.brfs.disknode.fileformat.impl.SimpleFileFormater) OpenMessageHandler(com.bonree.brfs.disknode.server.handler.OpenMessageHandler)

Example 2 with FileWriterManager

use of com.bonree.brfs.disknode.data.write.FileWriterManager in project BRFS by zhangnianli.

the class DataNodeBootStrap method start.

@Override
public void start() throws Exception {
    createRootDirIfNeeded(diskContext.getRootDir());
    RecordCollectionManager recorderManager = new RecordCollectionManager();
    writerManager = new FileWriterManager(recorderManager);
    writerManager.start();
    writerManager.rebuildFileWriterbyDir(diskContext.getRootDir());
    LOG.info("####################################come here###################################");
    FileFormater fileFormater = new SimpleFileFormater(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_MAX_CAPACITY));
    threadPool = Executors.newFixedThreadPool(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_REQUEST_HANDLER_NUM), new PooledThreadFactory("message_handler"));
    MessageChannelInitializer initializer = new MessageChannelInitializer(threadPool);
    initializer.addMessageHandler(TYPE_OPEN_FILE, new OpenFileMessageHandler(diskContext, writerManager));
    initializer.addMessageHandler(TYPE_WRITE_FILE, new WriteFileMessageHandler(diskContext, writerManager, fileFormater));
    initializer.addMessageHandler(TYPE_CLOSE_FILE, new CloseFileMessageHandler(diskContext, writerManager, fileFormater));
    initializer.addMessageHandler(TYPE_DELETE_FILE, new DeleteFileMessageHandler(diskContext, writerManager));
    initializer.addMessageHandler(TYPE_PING_PONG, new PingPongMessageHandler());
    initializer.addMessageHandler(TYPE_FLUSH_FILE, new FlushFileMessageHandler(diskContext, writerManager));
    initializer.addMessageHandler(TYPE_METADATA, new MetadataFetchMessageHandler(diskContext, writerManager, fileFormater));
    initializer.addMessageHandler(TYPE_LIST_FILE, new ListFileMessageHandler(diskContext));
    initializer.addMessageHandler(TYPE_RECOVER_FILE, new FileRecoveryMessageHandler(diskContext, serviceManager, writerManager, fileFormater, readerGroup));
    ServerConfig config = new ServerConfig();
    config.setBacklog(Integer.parseInt(System.getProperty(SystemProperties.PROP_NET_BACKLOG, "2048")));
    config.setBossThreadNums(1);
    config.setWorkerThreadNums(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_SERVER_IO_NUM));
    config.setPort(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_PORT));
    config.setHost(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_HOST));
    server = new TcpServer(config, initializer);
    server.start();
    ServerConfig fileServerConfig = new ServerConfig();
    fileServerConfig.setBacklog(Integer.parseInt(System.getProperty(SystemProperties.PROP_NET_BACKLOG, "2048")));
    fileServerConfig.setBossThreadNums(1);
    fileServerConfig.setWorkerThreadNums(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_READER_NUM));
    fileServerConfig.setPort(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_PORT));
    fileServerConfig.setHost(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_HOST));
    FileChannelInitializer fileInitializer = new FileChannelInitializer(new ReadObjectTranslator() {

        @Override
        public long offset(long offset) {
            return fileFormater.absoluteOffset(offset);
        }

        @Override
        public int length(int length) {
            return length;
        }

        @Override
        public String filePath(String path) {
            return diskContext.getConcreteFilePath(path);
        }
    });
    fileServer = new TcpServer(fileServerConfig, fileInitializer);
    fileServer.start();
}
Also used : RecordCollectionManager(com.bonree.brfs.disknode.data.write.record.RecordCollectionManager) CloseFileMessageHandler(com.bonree.brfs.disknode.server.tcp.handler.CloseFileMessageHandler) PooledThreadFactory(com.bonree.brfs.common.utils.PooledThreadFactory) FlushFileMessageHandler(com.bonree.brfs.disknode.server.tcp.handler.FlushFileMessageHandler) FileWriterManager(com.bonree.brfs.disknode.data.write.FileWriterManager) MessageChannelInitializer(com.bonree.brfs.common.net.tcp.MessageChannelInitializer) FileChannelInitializer(com.bonree.brfs.common.net.tcp.file.FileChannelInitializer) TcpServer(com.bonree.brfs.common.net.tcp.TcpServer) ServerConfig(com.bonree.brfs.common.net.tcp.ServerConfig) ReadObjectTranslator(com.bonree.brfs.common.net.tcp.file.ReadObjectTranslator) PingPongMessageHandler(com.bonree.brfs.disknode.server.tcp.handler.PingPongMessageHandler) DeleteFileMessageHandler(com.bonree.brfs.disknode.server.tcp.handler.DeleteFileMessageHandler) MetadataFetchMessageHandler(com.bonree.brfs.disknode.server.tcp.handler.MetadataFetchMessageHandler) ListFileMessageHandler(com.bonree.brfs.disknode.server.tcp.handler.ListFileMessageHandler) FileFormater(com.bonree.brfs.disknode.fileformat.FileFormater) SimpleFileFormater(com.bonree.brfs.disknode.fileformat.impl.SimpleFileFormater) OpenFileMessageHandler(com.bonree.brfs.disknode.server.tcp.handler.OpenFileMessageHandler) WriteFileMessageHandler(com.bonree.brfs.disknode.server.tcp.handler.WriteFileMessageHandler) FileRecoveryMessageHandler(com.bonree.brfs.disknode.server.tcp.handler.FileRecoveryMessageHandler) SimpleFileFormater(com.bonree.brfs.disknode.fileformat.impl.SimpleFileFormater)

Aggregations

PooledThreadFactory (com.bonree.brfs.common.utils.PooledThreadFactory)2 FileWriterManager (com.bonree.brfs.disknode.data.write.FileWriterManager)2 RecordCollectionManager (com.bonree.brfs.disknode.data.write.record.RecordCollectionManager)2 FileFormater (com.bonree.brfs.disknode.fileformat.FileFormater)2 SimpleFileFormater (com.bonree.brfs.disknode.fileformat.impl.SimpleFileFormater)2 NettyHttpRequestHandler (com.bonree.brfs.common.net.http.netty.NettyHttpRequestHandler)1 NettyHttpServer (com.bonree.brfs.common.net.http.netty.NettyHttpServer)1 MessageChannelInitializer (com.bonree.brfs.common.net.tcp.MessageChannelInitializer)1 ServerConfig (com.bonree.brfs.common.net.tcp.ServerConfig)1 TcpServer (com.bonree.brfs.common.net.tcp.TcpServer)1 FileChannelInitializer (com.bonree.brfs.common.net.tcp.file.FileChannelInitializer)1 ReadObjectTranslator (com.bonree.brfs.common.net.tcp.file.ReadObjectTranslator)1 CloseMessageHandler (com.bonree.brfs.disknode.server.handler.CloseMessageHandler)1 DeleteMessageHandler (com.bonree.brfs.disknode.server.handler.DeleteMessageHandler)1 FileLengthMessageHandler (com.bonree.brfs.disknode.server.handler.FileLengthMessageHandler)1 FlushMessageHandler (com.bonree.brfs.disknode.server.handler.FlushMessageHandler)1 ListMessageHandler (com.bonree.brfs.disknode.server.handler.ListMessageHandler)1 OpenMessageHandler (com.bonree.brfs.disknode.server.handler.OpenMessageHandler)1 PingPongRequestHandler (com.bonree.brfs.disknode.server.handler.PingPongRequestHandler)1 ReadMessageHandler (com.bonree.brfs.disknode.server.handler.ReadMessageHandler)1