How can I clear a dynamic knob after using `setknob` on `fdbcli`?

It appears that there is a setknob and getknob CLI command, but no command to clearknob. I know in theory that I could probably do a regular clear to clear the key from the configuration table, but I don’t know exactly how to do that.

Good catch! You are right, there is no clearknob fdbcli command. To run a clear transaction to manually clear the knob value in the configuration database, you can write something like this

import fdb

fdb.api_version(720)

@fdb.transactional
def print_knob(tr, knob_name, config_class):
        print(tr.get(fdb.tuple.pack((config_class, knob_name,))))

@fdb.transactional
def set_knob(tr, knob_name, knob_value, config_class, description):
        tr[b'\xff\xff/description'] = description
        tr[fdb.tuple.pack((config_class, knob_name,))] = knob_value

@fdb.transactional
def clear_knob(tr, knob_name, config_class, description):
        tr[b'\xff\xff/description'] = description
        tr.clear(fdb.tuple.pack((config_class, knob_name,)))

db = fdb.open()
db.options.set_use_config_database()

set_knob(db, 'min_trace_severity', b'20', None, b'description')
print_knob(db, 'min_trace_severity', None)
clear_knob(db, 'min_trace_severity', None, b'description')
print_knob(db, 'min_trace_severity', None)

https://github.com/apple/foundationdb/blob/main/design/dynamic-knobs.md has some more info on client uses of the configuration database if you haven’t already seen it.

1 Like

Thanks Lukas, this is helpful! Is it possible to do the same thing using the FDB CLI via a manual begin transaction? Or are client libraries the only way?

There is no way to clear a knob using fdbcli today, because configuration database transactions don’t go through the normal FDB key space. Instead, they use a separate transaction object with a bunch of differentiated logic for quorum logic, retry attempts, error handling etc… So you can’t run clear on a key from an FDB transaction. This is what the db.options.set_use_config_database() line in the above script is for. It causes newly created transactions to use the separate configuration database transaction objects.

I submitted a PR to add clearknob support to fdbcli Add `clearknob` fdbcli command by sfc-gh-ljoswiak · Pull Request #10818 · apple/foundationdb · GitHub. If you are able to build from main you can take advantage of it, otherwise the client libraries will be your only option for now.