Merging Existing Space-Tokens

When we setup space-tokens for AGLT2 we assumed we needed a space-token for each VO/Role that needed to be able to write to a space-token area. However we later found out that any VO/Role can write to an area as long as it knows the space-token. (Other methods may be used to limit write access)

At this point we have a number of areas with more than one used space token:

dcache=> select id,vogroup,vorole,usedspaceinbytes,linkgroupid from srmspace where vogroup<>'star' and usedspaceinbytes>0 order by linkgroupid;
    id    |    vogroup     |   vorole   | usedspaceinbytes | linkgroupid
----------+----------------+------------+------------------+-------------
 10063094 | /atlas         | production |     206539479519 |      210000
   570010 | /atlas         | production |  136996017023001 |      210000
   210005 | usatlas3       |            |       6073921667 |      210000
   570000 | /atlas/usatlas | production |    9602966589599 |      210000
   570011 | /atlas         | production |   46768872243156 |      390027
   570001 | /atlas/usatlas | production |    2781967985943 |      390027
   610961 | /atlas         | production |    1524399103887 |      610698
   610963 | /atlas/usatlas | production |   18444489710254 |      610699
   610964 | /atlas         | production |    4953359722760 |      610699
   781750 | /atlas         | production |   18055974649161 |      781688
   840526 | /atlas/usatlas | production |    2606242108298 |      781688
   980400 | /atlas/usatlas | production |   28837529635214 |      980399
  3567403 | /atlas/usatlas | software   |    1742900222989 |      980399
   980401 | /atlas         | production |    1360993825782 |      980399
(14 rows)

This page shows how we merge the space-tokens into one for each linkgroupid.

Structure of Relevant Tables

On head01.aglt2.org, the srmspace and srmspacefile tables track the space tokens. Their description:

srmspace
dcache=> \d srmspace;
                   Table "public.srmspace"
        Column         |           Type           | Modifiers
-----------------------+--------------------------+-----------
 id                    | bigint                   | not null
 vogroup               | character varying(32672) |
 vorole                | character varying(32672) |
 retentionpolicy       | integer                  |
 accesslatency         | integer                  |
 linkgroupid           | bigint                   |
 sizeinbytes           | bigint                   |
 creationtime          | bigint                   |
 lifetime              | bigint                   |
 description           | character varying(32672) |
 state                 | integer                  |
 usedspaceinbytes      | bigint                   |
 allocatedspaceinbytes | bigint                   |
Indexes:
    "srmspace_pkey" PRIMARY KEY, btree (id)
    "srmspace_creationtime_idx" btree (creationtime)
    "srmspace_description_idx" btree (description)
    "srmspace_lifetime_idx" btree (lifetime)
    "srmspace_linkgroupid_idx" btree (linkgroupid)
    "srmspace_state_idx" btree (state)
Foreign-key constraints:
    "fk_srmspace_a" FOREIGN KEY (accesslatency) REFERENCES srmaccesslatency(id)
    "fk_srmspace_l" FOREIGN KEY (linkgroupid) REFERENCES srmlinkgroup(id)
    "fk_srmspace_r" FOREIGN KEY (retentionpolicy) REFERENCES srmretentionpolicy(
id) ON DELETE RESTRICT

srmspacefile
dcache=> \d srmspacefile;
                Table "public.srmspacefile"
       Column       |           Type           | Modifiers
--------------------+--------------------------+-----------
 id                 | bigint                   | not null
 vogroup            | character varying(32672) |
 vorole             | character varying(32672) |
 spacereservationid | bigint                   |
 sizeinbytes        | bigint                   |
 creationtime       | bigint                   |
 lifetime           | bigint                   |
 pnfspath           | character varying(32672) |
 pnfsid             | character varying(32672) |
 state              | integer                  |
 deleted            | integer                  |
Indexes:
    "srmspacefile_pkey" PRIMARY KEY, btree (id)
    "srmspacefile_creationtime_idx" btree (creationtime)
    "srmspacefile_lifetime_idx" btree (lifetime)
    "srmspacefile_pnfsid_idx" btree (pnfsid)
    "srmspacefile_pnfspath_idx" btree (pnfspath)
    "srmspacefile_spacereservationid_idx" btree (spacereservationid)
    "srmspacefile_state_idx" btree (state)
Foreign-key constraints:
    "fk_srmspacefile_l" FOREIGN KEY (spacereservationid) REFERENCES srmspace(id) ON DELETE RESTRICT

The srmspace table tracks the space-token details (usage, allocation, owner) while the srmspacefile table tracks each files information. As an example, looking at the srmspacefile table for the first 10 files using space token 570000 gives:

dcache=> select id,spacereservationid,sizeinbytes,pnfsid,state from srmspacefile where spacereservationid=570000 limit 10;
   id    | spacereservationid | sizeinbytes |          pnfsid          | state
---------+--------------------+-------------+--------------------------+-------
 6642227 |             570000 |  1417452359 | 00050000000000000679DA38 |     2
 6642943 |             570000 |    85270590 | 0005000000000000067A2B80 |     2
 6562944 |             570000 |   259020610 | 0005000000000000066BDF68 |     2
 6646036 |             570000 |  1447345618 | 0005000000000000067A5578 |     2
 6646106 |             570000 |  1457643544 | 0005000000000000067A5F18 |     2
 6646101 |             570000 |  1442438352 | 0005000000000000067A5E70 |     2
 6646102 |             570000 |  1462132189 | 0005000000000000067A5EE0 |     2
 6646138 |             570000 |  1449607851 | 0005000000000000067A63D8 |     2
 6646167 |             570000 |  1453420206 | 0005000000000000067A6758 |     2
 6646182 |             570000 |  1446867921 | 0005000000000000067A68D0 |     2
(10 rows)

The id unique identifies each record, the spacereservationid shows which space-token is accounting for this file, the sizeinbytes is just that and the pnfsid is the pointer to the relevant file. So now we can see how to merge different space-tokens for a given linkgroup:

  • Run an SQL UPDATE to reassign all files from one spacereservationid to another
  • Update the accounting for the srmspace table to account for the change

Before doing anything backup the db as the postgres user: 'pg_dump dcache > /tmp/dcache_backup.psql'

Now for the first part we need to run a commands like (one per existing space-token to merge):

dcache=> update srmspacefile set spacereservationid=570010 where spacereservationid=570000;
UPDATE 73653
dcache=> update srmspacefile set spacereservationid=570010 where spacereservationid=210005;
UPDATE 323

Then for part two we need to update the srmspace table like:

update srmspace set usedspaceinbytes=(select coalesce (sum(sf.sizeinbytes),0) from srmspace s left outer join srmspacefile sf on s.id=sf.spacereservationid and sf.state=2 and s.id=srmspace.id);

update srmspace set allocatedSpaceInBytes=(select coalesce (sum(sf.sizeinbytes),0) from srmspace s left outer join srmspacefile sf on s.id=sf.spacereservationid and sf.state<2 and s.id=srmspace.id);

At this point we can verify we have released all the files in the space-tokens we merged and then "release" the empty (extra) space-tokens.

-- ShawnMcKee - 09 Oct 2009
Topic revision: r2 - 09 Oct 2009, ShawnMcKee
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback