commit map
Commit a transaction of map file changes.
Description
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.
Examples
In this example, we first use show map
to display the ID number of the map file and the version number of the transaction.
$ echo "show map" | \
sudo socat stdio unix-connect:/var/run/hapee-2.4/hapee-lb.sock
# id (file) description
2 (/etc/hapee-2.4/maps/routes.map) pattern loaded from file '/etc/hapee-2.4/maps/routes.map' used by map at file '/etc/hapee-2.4/hapee-lb.cfg' line 89. curr_ver=0 next_ver=1 entry_cnt=1
Confirm the entries in the transaction:
$ echo "show map @1 #2" | \
sudo socat stdio unix-connect:/var/run/hapee-2.4/hapee-lb.sock
0x560371c93640 /cart/ be_cart
Commit the transaction:
echo "commit map @1 #2" | \
sudo socat stdio unix-connect:/var/run/hapee-2.4/hapee-lb.sock
Contextual Example
This operation can be performed as part of a series of operations used to manage map files. The example in this section demonstrates how to modify mappings in HAProxy Enterprise's running configuration. The mappings are not persisted to the map file on disk. Any changes you make via the Runtime API are lost when the proxy halts.
Assume that you have a map file named /etc/hapee-2.4/routes.map
with the following contents where the first column contains the keys and the second contains the values:
/cart/ cart_api
/reviews/ reviews_api
In the HAProxy Enterprise configuration, we reference this map file on a use_backend
line with the map_beg
fetch method. This tells the load balancer to choose the backend from the map file by matching the beginning of the requested URL path with a key in the file:
frontend fe_main
bind :80
use_backend %[path,map_beg(/etc/hapee-2.4/routes.map,be_servers)]
-
Use the
show maps
command to list map files and their unique IDs. Here, the map file /etc/hapee-2.4/routes.map has an ID of 0:$ echo "show map" | \ sudo socat stdio unix-connect:/var/run/hapee-2.4/hapee-lb.sock
# id (file) description 0 (/etc/hapee-2.4/routes.map) pattern loaded from file '/etc/hapee-2.4/routes.map' used by map at file '/etc/hapee-2.4/hapee-lb.cfg' line 61. curr_ver=0 next_ver=1 entry_cnt=0
-
Pass the map file's unique ID to
show map
to display entries in the file:$ echo "show map #0" | \ sudo socat stdio unix-connect:/var/run/hapee-2.4/hapee-lb.sock
0x563bbeeee160 /cart/ cart_api 0x563bbeeee1a0 /reviews/ reviews_api
-
Pass the map file's unique ID to
prepare map
to start a transaction for map changes. Note the version number, which will be required in later commands. You can display version numbers using theshow acl
operation.$ echo "prepare map #0" | \ sudo socat stdio unix-connect:/var/run/hapee-2.4/hapee-lb.sock
New version created: 1
-
Execute the
set map
command with these arguments: the map's ID, the key to be modified, and a new value to replace the key's existing value.Alternatively, use the map file's path instead of its ID.
In the example below, we modify the /cart/ key, replacing the value cart_api with the value web_servers:
$ echo "set map #0 /cart/ web_servers" | \ sudo socat stdio unix-connect:/var/run/hapee-2.4/hapee-lb.sock
-
Call
commit map
with the version and map ID to commit the change and make it active in runtime memory:$ echo "commit map @1 #0" | \ sudo socat stdio unix-connect:/var/run/hapee-2.4/hapee-lb.sock
-
Call
show map
to confirm the modification:$ echo "show map #0" | \ sudo socat stdio unix-connect:/var/run/hapee-2.4/hapee-lb.sock
0x563bbeeee160 /cart/ web_servers 0x563bbeeee1a0 /reviews/ reviews_api
See also
Next up
commit ssl cert