0

我正在尝试实现一个利用 apache bookkeeper 的简单应用程序。

我正在使用以下 docker-compose 创建本地部署。

version: '2'

services:

  zookeeper:
    image: zookeeper
    hostname: zookeeper
    ports:
      - 2181:2181
    environment:
      - ZK_maxSessionTimeout=100

  bookie1:
    image: apache/bookkeeper
    hostname: bookie1
    links:
      - zookeeper
    environment:
      - JAVA_HOME=/usr/lib/jvm/java-11
      - BK_zkServers=zookeeper:2181
      - BK_zkLedgersRootPath=/ledgers
      - BK_httpServerPort=8080

  bookie2:
    image: apache/bookkeeper
    hostname: bookie2
    links:
      - zookeeper
    environment:
      - JAVA_HOME=/usr/lib/jvm/java-11
      - BK_zkServers=zookeeper:2181
      - BK_zkLedgersRootPath=/ledgers
      - BK_httpServerPort=8080

  bookie3:
    image: apache/bookkeeper
    hostname: bookie3
    links:
      - zookeeper
    environment:
      - JAVA_HOME=/usr/lib/jvm/java-11
      - BK_zkServers=zookeeper:2181
      - BK_zkLedgersRootPath=/ledgers
      - BK_httpServerPort=8080

这似乎运行成功。

在Java方面,我有以下代码:

public class Logger implements Closeable {

    final static String ZOOKEEPER_SERVER = "127.0.0.1:2181";
    final static byte[] LOGS_LEDGER_PASSWORD = "password".getBytes();
    int numberOfEntries = 0;
    BookKeeper bookkeeper;
    LedgerHandle ledgerHandle;
    long ledgerId;

    Logger() throws Exception {
        bookkeeper = new BookKeeper(ZOOKEEPER_SERVER);
        ledgerHandle = bookkeeper.createLedger(BookKeeper.DigestType.MAC, LOGS_LEDGER_PASSWORD);
        ledgerId = ledgerHandle.getId();
    }

    public void AddLog(String message) throws Exception {
        ledgerHandle.addEntry(message.getBytes());
        numberOfEntries++;
    }

    @Override
    public void close() {
    }

    public static void main(String[] args) throws Exception {
        Logger logger = new Logger();
        try {
            logger.AddLog("Yahya");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            logger.close();
        }
    }
}

bookkeeper.createLedger 没有抱怨,但我总是得到

org.apache.bookkeeper.client.BKException$BKNotEnoughBookiesException

执行时ledgerHandle.addEntry(message.getBytes())

ZooKeeper 容器日志:

2022-02-28 13:02:52,329 [myid:1] - WARN [NIOWorkerThread-7:NIOServerCnxn@371] - 意外异常 EndOfStreamException:无法从客户端读取其他数据,它可能关闭了套接字:地址 = /172.29。 0.3:38102, session = 0x10001cfa38d0000 at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:333) at org.apache.zookeeper.server.NIOServerCnxn.handleFailedRead(NIOServerCnxn.java:170) at org.apache。 zookeeper.server.NIOServerCnxnFactory$IOWorkRequest.doWork(NIOServerCnxnFactory.java:508) at org.apache.zookeeper.server.WorkerService$ScheduledWorkRequest.run(WorkerService.java:154) at java.base/java.util.concurrent.ThreadPoolExecutor。 runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) 2022-02-28 13:02: 52,443 [myid:1] - WARN [NIOWorkerThread-12:NIOServerCnxn@371] - 意外异常 EndOfStreamException:无法从客户端读取附加数据,它可能关闭了套接字:地址 = /172.29.0.3:38104,会话 = org.apache.zookeeper 的 0x10001cfa38d0001 .server.NIOServerCnxn.handleFailedRead(NIOServerCnxn.java:170) at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:333) at org.apache.zookeeper.server.NIOServerCnxnFactory$IOWorkRequest.doWork(NIOServerCnxnFactory.java :508) at org.apache.zookeeper.server.WorkerService$ScheduledWorkRequest.run(WorkerService.java:154) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util .concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) 2022-02-28 13:02:52,552 [myid:1] - WARN [NIOWorkerThread-3:NIOServerCnxn@371] - 意外异常 EndOfStreamException:无法从客户端读取附加数据,它可能关闭了套接字:地址 = /172.29.0.3:38106,会话 = 0x10001cfa38d0002 at org.apache.zookeeper.server.NIOServerCnxn.handleFailedRead(NIOServerCnxn. java:170) at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:333) at org.apache.zookeeper.server.NIOServerCnxnFactory$IOWorkRequest.doWork(NIOServerCnxnFactory.java:508) at org.apache.zookeeper .server.WorkerService$ScheduledWorkRequest.run(WorkerService.java:154) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run( Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) 2022-02-28 13:02:52,981 [myid:1] - WARN [NIOWorkerThread-10:NIOServerCnxn@371] - 意外异常 EndOfStreamException:无法从客户端读取附加数据,它可能关闭了套接字:地址 = /172.29.0.4:47484,会话 = 0x10001cfa38d0003 at org.apache.zookeeper.server.NIOServerCnxn.handleFailedRead(NIOServerCnxn. java:170) at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:333) at org.apache.zookeeper.server.NIOServerCnxnFactory$IOWorkRequest.doWork(NIOServerCnxnFactory.java:508) at org.apache.zookeeper .server.WorkerService$ScheduledWorkRequest.run(WorkerService.java:154) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run( Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) 2022-02-28 13:02:53,105 [myid:1] - WARN [NIOWorkerThread-1:NIOServerCnxn@371] - 意外异常 EndOfStreamException:无法从客户端读取附加数据,它可能关闭了套接字:地址 = /172.29.0.4:47488,会话 = 0x10001cfa38d0005 at org.apache.zookeeper.server.NIOServerCnxn.handleFailedRead(NIOServerCnxn. java:170) at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:333) at org.apache.zookeeper.server.NIOServerCnxnFactory$IOWorkRequest.doWork(NIOServerCnxnFactory.java:508) at org.apache.zookeeper .server.WorkerService$ScheduledWorkRequest.run(WorkerService.java:154) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run( Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) 2022-02-28 13:02:53,163 [myid:1] - WARN [NIOWorkerThread-8:NIOServerCnxn@371] - 意外异常 EndOfStreamException:无法从客户端读取附加数据,它可能关闭了套接字:地址 = /172.29.0.5:54222,会话 = 0x10001cfa38d0006 at org.apache.zookeeper.server.NIOServerCnxn.handleFailedRead(NIOServerCnxn. java:170) at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:333) at org.apache.zookeeper.server.NIOServerCnxnFactory$IOWorkRequest.doWork(NIOServerCnxnFactory.java:508) at org.apache.zookeeper .server.WorkerService$ScheduledWorkRequest.run(WorkerService.java:154) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run( Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) 2022-02-28 13:02:53,328 [myid:1] - WARN [NIOWorkerThread-15:NIOServerCnxn@371] - 意外异常 EndOfStreamException:无法从客户端读取附加数据,它可能关闭了套接字:地址 = /172.29.0.5:54224,会话 = 0x10001cfa38d0007 at org.apache.zookeeper.server.NIOServerCnxn.handleFailedRead(NIOServerCnxn. java:170) at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:333) at org.apache.zookeeper.server.NIOServerCnxnFactory$IOWorkRequest.doWork(NIOServerCnxnFactory.java:508) at org.apache.zookeeper .server.WorkerService$ScheduledWorkRequest.run(WorkerService.java:154) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run( Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) 2022-02-28 13:03:03,716 [myid:1] - INFO [SessionTracker:ZooKeeperServer@628] - 会话过期 0x10001cfa38d0005,超时时间超过 10000 毫秒 2022-02-28 13:03:03,716 [myid:1] - 信息 [SessionTracker:ZooKeeperServer@628] - 会话过期 0x10001cfa38d0006,超时时间超过 10000 毫秒

4

0 回答 0