Enable stateful functions

Enable stateful functions - 图1note

When the stateful APIs of Pulsar Functions are required – for example, putState() and queryState() related interfaces – you need to enable the stateful function feature in function workers.

  1. Enable the streamStorage service in BookKeeper. Currently, the service uses the NAR package, so you need to set the configuration in the conf/bookkeeper.conf file.

    1. ##################################################################
    2. ##################################################################
    3. # Settings below are used by stream/table service
    4. ##################################################################
    5. ##################################################################
    6. ### Grpc Server ###
    7. # the grpc server port to listen on. default is 4181
    8. storageserver.grpc.port=4181
    9. ### Dlog Settings for table service ###
    10. #### Replication Settings
    11. dlog.bkcEnsembleSize=3
    12. dlog.bkcWriteQuorumSize=2
    13. dlog.bkcAckQuorumSize=2
    14. ### Storage ###
    15. # local storage directories for storing table ranges data (e.g. rocksdb sst files)
    16. storage.range.store.dirs=data/bookkeeper/ranges
    17. # whether the storage server capable of serving readonly tables. default is false.
    18. storage.serve.readonly.tables=false
    19. # the cluster controller schedule interval, in milliseconds. default is 30 seconds.
    20. storage.cluster.controller.schedule.interval.ms=30000
  2. After starting the bookie, use the following methods to check whether the streamStorage service has been started successfully.

    • Input:

      1. telnet localhost 4181
    • Output:

      1. Trying 127.0.0.1...
      2. Connected to localhost.
      3. Escape character is '^]'.
  3. Configure stateStorageServiceUrl in the conf/functions_worker.yml file. bk-service-url is the service URL pointing to the BookKeeper table service.

    1. stateStorageServiceUrl: bk://<bk-service-url>:4181