Reference

commit map

Available since

  • HAProxy 2.4
  • HAProxy Enterprise 2.4r1

Commit a transaction of map file changes.

Description Jump to heading

Commit a transaction of map file changes. A transaction is initiated by executing the prepare map operation, which creates a new version of the map file. The version number is displayed as next_ver by the show map command. By specifying the version number and map ID or file name, you can make changes to the temporary map version using operations such as add map and clear map.

Committing the transaction makes the changes active in runtime memory and deletes all past versions of the map file in runtime memory. The operation is atomic. All changes represented in the transaction are applied together instantly, and any previous versions of the map are deleted from memory.

If no changes were made to the map version since the prepare map operation, performing the commit map operation effectively clears the map in runtime memory.

There is no abort map command. To abandon a transaction, simply do not commit it. Any uncommitted transaction is removed the next time you execute the prepare map command.

Examples Jump to heading

  1. Use the show maps command to list map files and their unique IDs.

    nix
    echo "show map" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    nix
    echo "show map" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    output
    text
    # id (file) description
    0 (/etc/hapee-2.8/routes.map) pattern loaded from file '/etc/hapee-2.8/routes.map' used by map at file '/etc/hapee-2.8/hapee-lb.cfg' line 61. curr_ver=0 next_ver=1 entry_cnt=0
    output
    text
    # id (file) description
    0 (/etc/hapee-2.8/routes.map) pattern loaded from file '/etc/hapee-2.8/routes.map' used by map at file '/etc/hapee-2.8/hapee-lb.cfg' line 61. curr_ver=0 next_ver=1 entry_cnt=0
  2. Pass the map file’s unique ID to show map to display entries in the file:

    nix
    echo "show map #0" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    nix
    echo "show map #0" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    output
    text
    0x563bbeeee160 /cart/ cart_api
    0x563bbeeee1a0 /reviews/ reviews_api
    output
    text
    0x563bbeeee160 /cart/ cart_api
    0x563bbeeee1a0 /reviews/ reviews_api
  3. Use prepare map to start a transaction.

    nix
    echo "prepare map #0" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    nix
    echo "prepare map #0" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    output
    text
    New version created: 1
    output
    text
    New version created: 1
  4. Delete all keys and values from the temporary transaction file.

    nix
    echo "clear map @1 #0" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    nix
    echo "clear map @1 #0" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
  5. Use commit map to apply the transaction.

    nix
    echo "commit map @1 #0" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    nix
    echo "commit map @1 #0" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999

See also Jump to heading

Do you have any suggestions on how we can improve the content of this page?