-1

I’d like to define some global configuration parameters to share them across sessions. How do I declare and define global variables in DolphinDB?

winnie
  • 183
  • 1
  • 6
FFF
  • 147
  • 1
  • 8

2 Answers2

0

you can define global variables using the global keyword.

global x = 1
Gaurav
  • 1
  • 1
0

Solution #1:

You can create a thread-safe dictionary which is shared across sessions. For example, create a global configuration file:

config = syncDict(STRING, STRING, `config)
config[`key1]=`value1
config[`key2]=`value2

Solution #2:

The first solution can only take effect on one node. To share configuration among nodes while maintaining the consistency, it is recommended to use a high-availability stream table.

colNames = `key`value`modifyTs
colTypes = [STRING, STRING, TIMESTAMP]
t=table(1000:0,colNames,colTypes)
haStreamTable(2, t,`global_config,10000000, keyColumn=`key, retentionMinutes=9999999)

In this case, you can even use DolphinDB as ZooKeeper. The configuration can be shared across the cluster, and can be restored after crash.

winnie
  • 183
  • 1
  • 6