0560 Monetdbd for Monetdb

Monetdbd is a MonetDB management daemon. We use it to:
– Initialize a directory as a DBfarm. A DBfarm is a folder that can contain several MonetDB databases.
– Monetdbd is used to set and read farm-wide daemon options that are shared between databases.
– Monetdbd is used to start/stop the actual servers (Mserver5 process).
– Users usually connect to the monetdbd daemon first, and then this daemon will redirect them to the selected database.

Monetdbd Informations

monetdbd -v
monetdbd --version
                                       
This is how we can find version of the monetdbd daemon. We can use short or long command syntax.

This is how we can get  help for monetdbd.  
monetdbd -h
monetdbd --help
We can provide the name of a command after the "-h" option. That will give us help for that command.

Monetdbd and DBfarm

cd /home/fffovde/Desktop
mkdir DBfarm
monetdbd create DBfarm

                                                     
We will create a folder with the name "DBfarm". With the command "monetdbd create", we will initialize this folder. Inside of it, a new file ".merovingian_properties" will appear. Now it is possible to create new databases inside of this folder.

This is the inside of the ".merovingian_properties" file.

Currently no one is listening to default MonetDB port 50.000. I will make DBfarm directory functional.  

monetdbd start DBfarm
Now our daemon is listening to port 50000, and DBfarm is functional.
ss -tlnp | grep 50000

After the first start of the DBfarm, three new files will appear in the DBfarm directory. ".merovingian_lock" file is empty."merovingian.pid" file has process ID for monetdbd process. We can confirm that with "pgrep monetdbd".                                                  

"merovingian.log" file is a file with a log.
We can stop DBfarm with monetdbd.  
monetdbd stop DBfarm
After closing the farm, file "merovingian.pid" will disappear. This file exists only when DBfarm is functional. Now, again, no one is listening to port 50.000. ss -tlnp | grep 50000

Getting and Setting DBfarm Settings

We can read setttings of the DBFarm.  

monetdbd get all DBfarm  
hostname              FffOvdeKomp
dbfarm                DBfarm
status                no monetdbd is serving this dbfarm
mserver               unknown (monetdbd not running)
logfile               DBfarm/merovingian.log
pidfile               DBfarm/Merovingian.pid
loglevel              information
sockdir               /tmp
listenaddr            localhost
port                  50000
exittimeout           60
forward               proxy
discovery             true
discoveryttl          600
control               no
passphrase            <unset>
snapshotdir           <unset>
snapshotcompression   .tar.lz4
keepalive             60
mapisock              /tmp/.s.monetdb.50000
controlsock           /tmp/.s.merovingian.50000

We can easily change any of these settings. 
monetdbd set loglevel=debug DBfarm
                                                          
We can also change the settings while DBfarm is active, but some changes will become valid only after Monetdbd is restarted.

After we first change some property, a list of the properties and their values will appear in the ".merovingian_properties" file.

Not all of the properties that we can observer with the "get all" command will be listed here. Properties that do not appear here can not be changed with the "set" command. Those properties are informative and read only.

We should never make changes in this file manually. We should always use the "set" command.

Monetdbd Settings

We will take a look at settings that we can set with Monetdbd.

 File and Log Settings

We know that in DBfarm folder we have files "merovingian.log" and "merovingian.pid". I will choose to use two other files instead of them.    I will change the settings for "log" and "pid" files:
monetdbd set logfile=/home/fffovde/Desktop/logy.log DBfarm
monetdbd set pidfile=/home/fffovde/Desktop/pidy.pid DBfarm

I will start daemon again:
monetdbd start DBfarm

Now, we have two new files on the desktop.Inside of the "log" file, we have a log for monetdbd. Lines labeled with the MSG, are for information and warnings.

We can decide what will be logged in the log file. We can choose between modes "error, warning, information and debug".

error = only errorswarning = errors and warningsinformation = errors, warnings and informationdebug = the same as information

Error lines will be marked with ERR.Default is "information". This is how we change the mode:# monetdbd set loglevel=error DBfarm

Connection Settings

Settings "sockdir" and "forward" should almost never be changed.

Listendaddr is "localhost" by default. That means that our server is not available from the network.If I set listenaddr to "0.0.0.0", our server will become available from the network. I will also change default port number to 50001.

monetdbd set listenaddr=0.0.0.0 DBfarm
monetdbd set port=50001 DBfarm
This setting will become functional only after we restart monetdbd.
monetdbd stop DBfarm
monetdbd start DBfarm

Inside of the DBfarm, I will create and start one database:
monetdb create DBfarmDB
monetdb release DBfarmDB 

monetdb start DBfarmDB  
I will now open the green server. I explained creation of this server in this blog post "link". Then I will try to connect to DBfarmDB from the green server.
mclient -h 192.168.100.124 -p 50001 -u monetdb -d DBfarmDB

We can use any of these modes for "listenaddr". It is also possible to use "hostname", in that case Linux will resolve what will be used.

Loopback address:External host:
only IPv4127.0.0.10.0.0.0
only IPv6::1::
IPv4 and IPv6localhostall

I will change back the port number of the "voc" server to 50000: "monetdbd set port=50000 DBfarm".

Snapshot Settings

In the blog post "link", we have saw how to create a snapshot of our database. We have used stored procedure for that. The same is possible from the command line. Settings for command line snapshots are in monetdbd properties file.

"snapshotdir" is a directory where our snapshot will be made. If this is not set, then we will not be able to make a snapshot.monetdbd set snapshotdir=/home/fffovde/Desktop DBfarm
"snapshotcompression" is a level of compression. We can choose between "tar.lz4,tar.bz2,tar.gz,tar.xz". This is optional setting.monetdbd set snapshotcompression=.tar.lz4 DBfarm
There is a dot before "tar".

I will set these changes, and then we will create a snapshot. We will create snapshot with the "monetdb" console program.

monetdb snapshot create DBfarmDB
This will create ".tar.lz4" snapshot on our Desktop. Inside of it we will get "DBfarmDB" database.

We can unset a property by providing an empty value:monetdbd set snapshotdir= DBfarm

Remote Control Settings

We can call and control "monetdbd" on remote computer. I will allow remote control for "monetdbd" on the "voc" server.monetdbd set control=true DBfarm
We also have to provide SHA512 password.monetdbd set passphrase=zebra DBfarm
Our password will be written to ".merovingian_properties" file. It will be written as 128-digits hexadecimal number with the prefix "{SHA512}".
If we only have hashed password, then we can provide it directly.monetdbd set passphrase={SHA512}9df3424fec DBfarm
We have to restart monetdbd for these settings to become functional. We will also start DBfarmDB database.monetdbd stop DBfarm
monetdbd start DBfarm
monetdb start DBfarmDB

Remote control is established by using monetdb.

I will run this command from the green server, with monetdb. Now we can control monetdbd on the "voc" server remotely.monetdb -h 192.168.100.124 -p 50000 -P zebra stop DBfarmDB

   

Remote Discovery Settings

Monetdb can "shout" its existence on the local network by UDP broadcast. In regular intervals Monetdb server will tell other computers on the LAN about its existence. This is how we can discover all of the monetdb servers in our network.

I will tell "voc" server to broadcast its existence every 300 seconds. It will use default port 50000.

monetdbd set discovery=true DBfarm
monetdbd set discoveryttl=300 DBfarm
I will restart DBfarm.  

monetdbd stop DBfarm
monetdbd start DBfarm
                                            

On the green server I will run this command.
monetdb discover
We can see here that on the "voc" server (hostname fffOvdeKomp), we have database "DBfarmDB". We also see local green database. So, we get a list of all of the available databases.

Start and Stop Settings

monetdbd stop DBfarm monetdbd start -n DBfarmI will stop "DBfarm", and then I will start it with a "-n" switch.  This will leave "monetdbd" daemon in the foreground and will not return control to the shell (we will not get prompt in the next line). This is useful for debugging.

We can close "monetdbd" using "ctrl+C" and then Enter.

There is "monetdbd" setting "exittimeout" with the default value 60.


This means that "monetdbd" will ask "mserver" to shutdown politely with the SIGTERM command ( "mserver" can refuse ).
If the "mserver" is not closed after 60+5 seconds, then "monetdbd" will send SIGKILL signal, and "mserver" will be violently shut down.

There are three possible values for "exittimeout".POSITIVE VALUE:
"Mserver", if alive, will be killed 5 seconds after the "exittimeout".
NEGATIVE VALUE:
"Mserver" will only receive SIGTERM signal. It will never be killed.
ZERO:
"Monetdbd" will close, but "Mservers" will not. We should not use this.

When we wait for a really long query to finish, our client will not communicate with the server. Firewall can interpret that like an inactive connection, so it will close the connection. We want to avoid this, so we can use probe signal to keep connection alive.This is done with the "keepalive" setting, with the default value of 60 seconds.
# monetdbd set keepalive=60 DBfarm
This probe signal will be sent exactly 127 times. If "keepalive" time is 60 seconds, that means that are connection will be at least (127 x 60 seconds) ≈ 2 hours alive.

Monetdbd Return Value

Monetdbd will return "0" for successful action, and "1" for unsuccessful. If we try to start already started daemon, we will get an error.
monetdbd start DBfarm; echo $?

Monetdbd Process Signals

I will start the monetdbd again, and then I will read process ID of our daemon.
monetdbd start DBfarm
cat ./pidy.pid

Let's assume that I want to use some other file, instead of "logy.log", for logging, but I do not want to restart monetdbd. I will do that in the two steps.

monetdbd set logfile=/home/fffovde/Desktop/DBfarm/merovingian.log DBfarm
kill -HUP  "$(cat ./pidy.pid)"
I am changing the file for my log.
I am sending SIGHUP signal to monetdbd.

Now the daemon will stop using "logy.log" file, and will use "merovingian.log" file. We didn't have to restart the daemon.

We can kill monetdbd with a signal. All of the signals bellow work the same.
kill -TERM "$(cat "pidy.pid")"
kill -INT  "$(cat "pidy.pid")"
kill -QUIT "$(cat "pidy.pid")"
They will ask our "mserver5" process to gently end (it can refuse). Signals: SIGTERM
SIGINT
SIGQUIT

Leave a Comment

Your email address will not be published. Required fields are marked *