DB2 Version 10.1 for Linux, UNIX, and Windows

Rebalancing DMS containers

The process of rebalancing involves moving table space extents from one location to another, and it is done in an attempt to keep data striped within the table space. You typically rebalance a table space when adding storage paths to or dropping storage paths from a database.

Effect of adding or dropping containers on rebalancing

When a table space is created, its table space map is created and all of the initial containers are lined up such that they all start in stripe 0. This means that data is striped evenly across all of the table space containers until the individual containers fill up. (See Example 1 ("Before").)

Adding a container that is smaller than existing containers results in a uneven distribution of data. This can cause parallel I/O operations, such as prefetching data, to be performed less efficiently than they could on containers of equal size.

When new containers are added to a table space or existing containers are extended, a rebalance of the table space data will occur if the new space is added below the high water mark for the table space. If new space as added above the high water mark or if you are creating a new stripe set, a rebalance does not automatically occur. Rebalancing that is done to take advantage of added storage is known as a forward rebalance; in this case, the extent movement begins at extent 0 (the first extent in the table space) and proceeds upwards to the extent immediately below the high water mark.

Adding a container will almost always add space below the high-water mark, which is why a rebalance is often necessary when you add a container. You can force new containers to be added above the high-water mark, which allows you to choose not to rebalance the contents of the table space. An advantage of this method is that the new container will be available for immediate use. Adding containers to a table space without rebalancing is done by adding a new stripe set. A stripe set is a set of containers in a table space that has data striped across it separately from the other containers that belong to that table space. The existing containers in the existing stripe sets remain untouched, and the containers you add become part of a new stripe set. To add containers without rebalancing, use the BEGIN NEW STRIPE SET clause on the ALTER TABLESPACE statement.

When containers are dropped from a table space, a rebalance automatically occurs if data resides in the space being dropped. In this case, the rebalance is known as a reverse rebalance; the extent movement begins at the high water mark and proceeds downwards to the first extent in the table space.

Before the rebalance starts, a new table space map is built based on the container changes made. The rebalancer will move extents from their location determined by the current map into the location determined by the new map.

Forward rebalancing

The rebalancer starts at extent 0, moving one extent at a time until the extent holding the high-water mark has been moved. As each extent is moved, the current map is altered, one piece at a time, to look like the new map. When the rebalance is complete, the current map and new map should look identical up to the stripe holding the high-water mark. The current map is then made to look completely like the new map and the rebalancing process is complete. If the location of an extent in the current map is the same as its location in the new map, then the extent is not moved and no I/O takes place.

When adding a new container, the placement of that container within the new map depends on its size and the size of the other containers in its stripe set. If the container is large enough such that it can start at the first stripe in the stripe set and end at (or beyond) the last stripe in the stripe set, then it will be placed that way (see Example 1 ("After")). If the container is not large enough to do this, it will be positioned in the map such that it ends in the last stripe of the stripe set (see Example 3.) This is done to minimize the amount of data that needs to be rebalanced.

Access to the table space is not restricted during rebalancing; objects can be dropped, created, populated, and queried as usual. However, the rebalancing operation can have a significant impact on performance. If you need to add more than one container, and you plan to rebalance the containers, you should add them at the same time within a single ALTER TABLESPACE statement to prevent the database manager from having to rebalance the data more than once.

Note: In the following examples, the container sizes do not take the size of the container tag into account. The container sizes are very small, and are just used for the purpose of illustration, they are not recommended container sizes. The examples show containers of different sizes within a table space, but you are advised to use containers of the same size.

Reverse rebalancing

The rebalancer starts with the extent that contains the high-water mark, moving one extent at a time until extent 0 has been moved. As each extent is moved, the current map is altered one piece at a time to look like the new map. If the location of an extent in the current map is the same as its location in the new map, then the extent is not moved and no I/O takes place.

Examples

Example 1 (before): Table space layout before containers added

If you create a table space with three containers and an extent size of 10, and the containers are 60, 40, and 80 pages which equate to 6, 4, and 8 extents, the table space is created with a map that can be diagrammed as shown in Figure 1.

Figure 1. Table space with three containers and 18 extents
A table space in an array with eight stripes down the left side and three containers across the top.
The corresponding table space map, as shown in a table space snapshot, looks like this:
    Range     Stripe  Stripe  Max        Max    Start    End    Adj.   Containers
    Number    Set     Offset  Extent     Page   Stripe   Stripe 
       [0]       [0]       0      11      119        0        3    0   3 (0, 1, 2)
       [1]       [0]       0      15      159        4        5    0   2 (0, 2)
       [2]       [0]       0      17      179        6        7    0   1 (2)

The headings in the table space map are Range Number, Stripe Set, Stripe Offset, Maximum extent number addressed by the range, Maximum page number addressed by the range, Start Stripe, End Stripe, Range adjustment, and Container list.

Example 1 (after): Adding a container that results in a forward rebalance being performed

If an 80-page container is added to the table space in Example 1, the container is large enough to start in the first stripe (stripe 0) and end in the last stripe (stripe 7). It is positioned such that it starts in the first stripe. The resulting table space can be diagrammed as shown in Figure 2.

Figure 2. Table space with four containers and 26 extents
A table space in an array with eight stripes down the left side and four containers across the top.
The corresponding table space map, as shown in a table space snapshot, will look like this:
    Range     Stripe  Stripe  Max        Max    Start    End    Adj.   Containers
    Number    Set     Offset  Extent     Page   Stripe   Stripe 
       [0]       [0]       0      15      159        0        3    0   4 (0, 1, 2, 3)
       [1]       [0]       0      21      219        4        5    0   3 (0, 2, 3)
       [2]       [0]       0      25      259        6        7    0   2 (2, 3)

If the high-water mark is within extent 14, the rebalancer starts at extent 0 and moves all of the extents up to and including 14. The location of extent 0 within both of the maps is the same so this extent is not required to move. The same is true for extents 1 and 2. Extent 3 does need to move so the extent is read from the old location (second extent within container 0) and is written to the new location (first extent within container 3). Every extent after this up to and including extent 14 is moved. Once extent 14 is moved, the current map looks like the new map and the rebalancer terminates.

If the map is altered such that all of the newly added space comes after the high-water mark, then a rebalance is not necessary and all of the space is available immediately for use. If the map is altered such that some of the space comes after the high-water mark, then the space in the stripes above the high-water mark is available for use. The rest is not available until the rebalance is complete.

If you decide to extend a container, the function of the rebalancer is similar. If a container is extended such that it extends beyond the last stripe in its stripe set, the stripe set will expand to fit this and the following stripe sets will be shifted out accordingly. The result is that the container will not extend into any stripe sets following it.

Example 2: Extending a container

Consider the table space from Example 1. If you extend container 1 from 40 pages to 80 pages, the new table space looks like Figure 3.

Figure 3. Table space with three containers and 22 extents
A table space in an array with eight stripes down the left side and three containers across the top.
The corresponding table space map, as shown in a table space snapshot, looks like this:
    Range     Stripe  Stripe  Max        Max    Start    End    Adj.   Containers
    Number    Set     Offset  Extent     Page   Stripe   Stripe 
       [0]       [0]       0      17      179        0        5    0   3 (0, 1, 2)
       [1]       [0]       0      21      219        6        7    0   2 (1, 2)

Example 3: Adding a container not large enough to both start in the first stripe and end in the last

Consider the table space from Example 1. If a 50-page (5-extent) container is added to it, the container will be added to the new map in the following way. The container is not large enough to start in the first stripe (stripe 0) and end at or beyond the last stripe (stripe 7), so it is positioned such that it ends in the last stripe. (See Figure 4.)

Figure 4. Table space with four containers and 23 extents
A table space in an array with eight stripes down the left side and four containers across the top.
The corresponding table space map, as shown in a table space snapshot, will look like this:
    Range     Stripe  Stripe  Max        Max    Start    End    Adj.   Containers
    Number    Set     Offset  Extent     Page   Stripe   Stripe 
       [0]       [0]       0       8       89        0        2    0   3 (0, 1, 2)
       [1]       [0]       0      12      129        3        3    0   4 (0, 1, 2, 3)
       [2]       [0]       0      18      189        4        5    0   3 (0, 2, 3)
       [3]       [0]       0      22      229        6        7    0   2 (2, 3)

To extend a container, use the EXTEND or RESIZE clause on the ALTER TABLESPACE statement. To add containers and rebalance the data, use the ADD clause on the ALTER TABLESPACE statement. If you are adding a container to a table space that already has more than one stripe set, you can specify which stripe set you want to add to. To do this, you use the ADD TO STRIPE SET clause on the ALTER TABLESPACE statement. If you do not specify a stripe set, the default behavior will be to add the container to the current stripe set. The current stripe set is the most recently created stripe set, not the one that last had space added to it.

Any change to a stripe set might cause a rebalance to occur to that stripe set and any others following it.

You can monitor the progress of a rebalance by using table space snapshots. A table space snapshot can provide information about a rebalance such as the start time of the rebalance, how many extents have been moved, and how many extents must move.

Example 4: Dropping a container that results in a reverse rebalance being performed

Note: In the following examples, the container sizes do not take the size of the container tag into account. The container sizes are very small, and are just used for the purpose of illustration, they are not recommended container sizes. The examples show containers of different sizes within a table space, but this is just for the purpose of illustration; you are advised to use containers of the same size.

For example, consider a table space with three containers and an extent size of 10. The containers are 20, 50, and 50 pages respectively (2, 5, and 5 extents). The table space diagram is shown in Figure 5.

Figure 5. Table space with 12 extents, including four extents with no data
A table space in an array with five stripes down the left side and three containers across the top.

An X indicates that there is an extent but there is no data in it.

If you want to drop container 0, which has two extents, there must be at least two free extents above the high-water mark. The high-water mark is in extent 7, leaving four free extents, therefore you can drop container 0.

The corresponding table space map, as shown in a table space snapshot, will look like this:
    Range     Stripe  Stripe  Max        Max    Start    End    Adj.   Containers
    Number    Set     Offset  Extent     Page   Stripe   Stripe 
       [0]       [0]       0       5       59        0        1    0   3 (0, 1, 2)
       [1]       [0]       0      11      119        2        4    0   2 (1, 2)

After the drop, the table space will have just Container 0 and Container 1. The new table space diagram is shown in Figure 6.

Figure 6. Table space after a container is dropped
A table space in an array with five stripes down the left side and two containers across the top.
The corresponding table space map, as shown in a table space snapshot, will look like this:
    Range     Stripe  Stripe  Max        Max    Start    End    Adj.   Containers
    Number    Set     Offset  Extent     Page   Stripe   Stripe 
       [0]       [0]       0       9       99        0        4    0   2 (0, 1)

Example 5: Adding a new stripe set

If you have a table space with three containers and an extent size of 10, and the containers are 30, 40, and 40 pages (3, 4, and 4 extents respectively), the table space can be diagrammed as shown in Figure 7.

Figure 7. Table space with three containers and 11 extents
A table space in an array with four stripes down the left side and three containers across the top.
The corresponding table space map, as shown in a table space snapshot, will look like this:
    Range     Stripe  Stripe  Max        Max    Start    End    Adj.   Containers
    Number    Set     Offset  Extent     Page   Stripe   Stripe 
       [0]       [0]       0       8       89        0        2    0   3 (0, 1, 2)
       [1]       [0]       0      10      109        3        3    0   2 (1, 2)

When you add two new containers that are 30 pages and 40 pages (3 and 4 extents respectively) with the BEGIN NEW STRIPE SET clause, the existing ranges are not affected; instead, a new set of ranges is created. This new set of ranges is a stripe set and the most recently created one is called the current stripe set. After the two new containers is added, the table space looks like Figure 8.

Figure 8. Table space with two stripe sets
A table space in an array with eight stripes down the left side and five containers across the top.
The corresponding table space map, as shown in a table space snapshot, looks like this:
    Range     Stripe  Stripe  Max        Max    Start    End    Adj.   Containers
    Number    Set     Offset  Extent     Page   Stripe   Stripe 
       [0]       [0]       0       8       89        0        2    0   3 (0, 1, 2)
       [1]       [0]       0      10      109        3        3    0   2 (1, 2)
       [2]       [1]       4      16      169        4        6    0   2 (3, 4)
       [3]       [1]       4      17      179        7        7    0   1 (4)

If you add new containers to a table space, and you do not use the TO STRIPE SET clause with the ADD clause, the containers are added to the current stripe set (the highest stripe set). You can use the ADD TO STRIPE SET clause to add containers to any stripe set in the table space. You must specify a valid stripe set.

The database manager tracks the stripe sets using the table space map, and adding new containers without rebalancing generally causes the map to grow faster than when containers are rebalanced. When the table space map becomes too large, you will receive error SQL0259N when you try to add more containers.