## ###########################################################################
##           ____  _____ _____ _____ _____ _____ _____ _____ _____
##          |    \|   __|   __|  _  |  |  |  _  |  |  |   __|   | |
##          |  |  |   __|   __|   __|     |     |  |  |   __| | | |
##          |____/|_____|_____|__|  |__|__|__|__|\___/|_____|_|___|
##
##  ************       Example YAML Configuration File      ****************
##  ************  Copyright 2019 Deephaven Data Labs, LLC   ****************
##
##  This is an example file, illustrating features of the YAML configuration format.
##
## ############################################################################

config:
  anchors:
    # &name defines an anchor which allows "name" to be referenced elsewhere in the document
    # This is effectively a map of the cluster
    - &default-host "localhost"
    - &localhost    "localhost" # use this to be able to change how you refer to localhost
    - &dh-import    "localhost"
    - &dh-rta       "localhost"

    # Define aliases for the default port values
    - &default-tailerPort              22021
    - &default-lasPort                 22020
    - &default-tableDataPort           22015
    - &default-tableDataCacheProxyPort 22016
    - &default-localTableDataPort      22014

  storage:
    - name: default
      dbRoot: /db
    # define additional storage locations here
    #- name: Example_LastBy
    #  dbRoot: /db/dataImportServers/Example_LastBy

  # This section (name is arbitrary) defines an anchor with useful default
  # values for dataImportServers, logAggregatorServers, and others.
  defaults:
    # DIS-default defines an anchor that has default values for dataImportServers
    # entries. Instances below can override only what they need to change.
    - &DIS-default
      tailerPort: *default-tailerPort
      storage: default
      definitionsStorage: default
      tableDataPort: *default-tableDataPort
      # if a DIS instance adds a properties key, it will REPLACE this one. Add another anchor so they can be added back in.
      properties: &DIS-defaultProperties
        ## the following properties are available for import servers
        ## TableDataService properties
        #   requestTimeoutMillis: 60000
        # Start DIS Cache Hints
        # Note that failover import servers handling the same data must have identical settings per table
        # Table name and column name exact match:
        StringCacheHint.tableNameAndColumnNameEquals_QuoteArcaStock/Exchange: ConcurrentUnboundedStringCache,String,1
        #
        # Column name exact match:
        # NB: USym and Sym are still using Strings - in case of issues, this should keep ImportState instances compatible across bounces.
        StringCacheHint.columnNameEquals_USym: ConcurrentUnboundedStringCache,String,20000
        StringCacheHint.columnNameEquals_Sym: ConcurrentUnboundedStringCache,String,800000
        StringCacheHint.columnNameEquals_Exchange: ConcurrentUnboundedStringCache,CompressedString,50
        StringCacheHint.columnNameEquals_SecurityType: ConcurrentUnboundedStringCache,CompressedString,9
        StringCacheHint.columnNameEquals_Parity: ConcurrentUnboundedStringCache,CompressedString,2
        #
        # Everything else:
        StringCacheHint.default: ConcurrentBoundedStringCache,MappedCompressedString,1000000,2
        #
        ########## End DIS Cache Hints ##########

    # LAS-default defines an anchor that has default values for logAggregatorServers
    - &LAS-default
      port: *default-lasPort
      host: *localhost
      # if a LAS instance adds a properties key, it will REPLACE this one. Add another anchor so they can be added back in.
      properties: &LAS-defaultProperties
      ## the following properties are available for log aggregators
      #   binaryLogTimeZone: America/New_York
      #   messagePool.minBufferSize: 1024
      #   messagePool.maxBufferSize: 1048576
      #   messagePool.bucketSize: 1000
      #   BinaryLogQueueSink.pollTimeoutMs: 1000
      #   BinaryLogQueueSink.idleShutdownTimeoutMs: 300000 (5 minutes)
      #   BinaryLogQueueSink.queueSize: 1000

    - &LocalTableDataService-default
      # if a TDS instance adds a properties key, it will REPLACE this one. Add another anchor so they can be added back in.
      properties: &LocalTableDataService-defaultProperties
      ## the following properties are available for LocalTableDataService instances -
      ## that is, for tableDataServices which are LocalTableDataServices
      #  tableLocationsRefreshMillis: 10000
      #  tableSizeRefreshMillis: 30000
      #  requestTimeoutMillis: 60000
      #  allowLiveUserTables: false

  dataImportServers:
    # The primary data import server
    db_dis:
      # import the default values
      <<: *DIS-default
      host: *dh-import   # reference the address defined above for "dh-import"
      userIntradayDirectoryName: "IntradayUser"
      webServerParameters:
        enabled: true
        port: 8084
        authenticationRequired: false
        sslRequired: false
      filters:
      - {namespaceSet: System, online: true}
      properties:
        # re-add the default properties (omit the <<: if you don't want the defaults)
        <<: *DIS-defaultProperties
        ## any additional properties for this DIS

    # Define a data import server for user data
    # NOTE: as configured here, this import server is actually the same process as db_dis. It is provided for control over routing.
    #       since this is only for routing, userIntradayDirectoryName is not used, but set the same as db_dis to avoid confusion
    db_rta:
      <<: *DIS-default
      host: *dh-import
      userIntradayDirectoryName: "IntradayUser"
      tailerPort: *default-tailerPort
      filters: {namespaceSet: User}

    # This defines an in-worker lastBy import server
    #Example_LastBy:
    #  host: *dh-import
    #  tailerPort: 22222
    #  filters:
    #    - {namespace: LASTBY_NAMESPACE}
    #  webServerParameters:
    #    enabled: false
    #  storage: Example_LastBy
    #  tableDataPort: 22223

  # Filter matches will be "or" matches; The first match will be returned.
  logAggregatorServers: !!omap  # need an ordered map for precedence, to allow the filters to overlap
    # User data will go to the rta instance
    - rta:
        <<: *LAS-default
        host: *dh-rta
        filters:
          - namespaceSet: User

    # All other data goes to the log aggregator on localhost
    - log_aggregator_service: # default LAS
        <<: *LAS-default
        #properties:
        # optionally re-add the default properties if you add properties here
        # <<: *LAS-defaultProperties

  # The tableDataServices section defines single and composite table data services.
  # LocalTableDataService, TableDataCacheProxy, and other republishing processes will
  # typically select the name matching the process.name property.
  tableDataServices:
    # Note: dataImportServices entries are implicitly available for use in
    # tableDataService composition.

    # Define the default local (from disk) LocalTableDataService
    local:
      storage: default

    # Configuration for the LocalTableDataServer named db_ltds, and define
    # the data published by that service
    db_ltds:
      host: *dh-import
      port: *default-localTableDataPort
      storage: default
      <<: *LocalTableDataService-default
      #properties:
      # optionally re-add the default properties if you add properties here
      #  <<: *LocalTableDataService-defaultProperties
      #  tableLocationsRefreshMillis: 10000
      #  tableSizeRefreshMillis: 30000
      #  requestTimeoutMillis: 60000

    # Configuration for the TableDataCacheProxy named db_tdcp, and define
    # the data published by that service.
    # There is typically one such service on each worker machine.
    db_tdcp:
      host: *localhost
      port: *default-tableDataCacheProxyPort
      sources:
        # SYSTEM_INTRADAY tables for "current date"
        - name: db_dis
          filters: {whereTableKey: "NamespaceSet = `System` && Online", whereLocationKey: "ColumnPartition >= currentDateNy()"}
        # LTDS for SYSTEM_INTRADAY non-current date
        - name: db_ltds
          filters: {whereTableKey: "NamespaceSet = `System` && Online", whereLocationKey: "ColumnPartition < currentDateNy()"}
        # A db_rta source is useful in case it's different from db_dis
        - name: db_rta
          filters: {namespaceSet: User}

    # Example of tdcp which includes a lastBy import server
    #db_tdcp_with_lastby:
    #  host: *localhost
    #  port: *default-tableDataCacheProxyPort
    #  sources:
    #  # SYSTEM_INTRADAY tables for "current date", minus LASTBY_NAMESPACE tables handled by Example_LastBy
    #  - name: db_dis
    #    filters: {whereTableKey: "NamespaceSet = `System` && Namespace != `LASTBY_NAMESPACE`", whereLocationKey: "ColumnPartition >= currentDateNy()"}
    #  # LTDS for SYSTEM_INTRADAY non-current date, minus LASTBY_NAMESPACE tables handled by Example_LastBy
    #  - name: db_ltds
    #    filters: {whereTableKey: "NamespaceSet = `System` && Namespace != `LASTBY_NAMESPACE`", whereLocationKey: "ColumnPartition < currentDateNy()"}
    #  # all user data
    #  - name: db_rta
    #    filters: {namespaceSet: User}
    #  # only LASTBY_NAMESPACE data
    #  - name: Example_LastBy
    #    filters: {whereTableKey: "NamespaceSet = `System` && Namespace == `LASTBY_NAMESPACE`"}

    # Define the TableDataService for query servers with local filesystem access
    # to historical system data.
    query:
      sources:
      - name: local
        filters: {online: false } # (system and offline) or user
      - name: db_tdcp
        filters: {online: true}

    # Define the TableDataService for query servers without local filesystem access
    # to historical system data - use ltds instead.
    query_ltds:
      sources:
      - name: db_ltds
        filters: {whereTableKey: "Offline"}
      - name: db_tdcp
        filters: {whereTableKey: "Online"}
