Ask Your Question

How to create unique object names?

asked 2014-03-14 00:55:45 -0500

Martin Pitt gravatar image

updated 2014-03-14 00:59:16 -0500

In our (future) setup we have many worker nodes executing tests, which want to store log files and artifacts in swift. We want to keep the entire history, thus want to create a pseudo-directory structure like either

  • /project/version/67/, i. e. ascending numbers, or
  • /project/version/YYYYMMDD-HHMMS.n/, i. e. time stamp based, with an extra suffix if two workers write a log at the same time; that suffix could just be an ascending number or a mktemp-like suffix (which doesn't sort, though).

I did not find any way of either getting a global counter, or atomically creating an object so that other writers won't use the same pseudo-dir-name, or getting a lock for exclusive access.

One could dramatically reduce the probability of collisions by using the format YYYYMMDD-HHMMS.XXXXXX where the Xes are a tmpname() random suffix. But that looks ugly, destroys the sorted order (for traversing from most recent to older logs), and only makes the problem smaller but doesn't fix it.

How does one create unique object names with concurrent writers in swift?

Thanks in advance!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-03-17 18:57:03 -0500

torgomatic gravatar image

If you want unique names, you have to make sure the names you generate are unique. Swift won't help you here, as an object PUT will cheerfully overwrite an object of the same name.

In this case, it looks like you could use timestamps with microsecond or nanosecond precision (whatever you've got laying around) to give you ordering, plus a UUID to give you uniqueness in the rare case where two tests start on the same microsecond.

edit flag offensive delete link more


Thanks, I suspected something such. I just wanted to make sure to not miss anything.

Martin Pitt gravatar imageMartin Pitt ( 2014-03-18 01:46:25 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-03-14 00:55:45 -0500

Seen: 348 times

Last updated: Mar 17 '14