Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resource.UniqueId to be properly ordered #10152

Merged
merged 1 commit into from
Nov 21, 2016
Merged

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Nov 16, 2016

This isn't a major issue, and probably never encountered in real usage, but I was tired of my unit tests failing because time was used as a counter.

UniqueId attempted to provide an ordered unique id by using a nanosecond
timestamp, but doesn't take into account that time is not monotonic
increasing, nor do many system clocks have the resolution to return different times
when called in quick succession. This provides an implementation that will always be
increasing.

@jbardin jbardin force-pushed the jbardin/unique-id branch 2 times, most recently from c8d5eb4 to 8795ee4 Compare November 16, 2016 02:50
UniqueId attempted to provide an ordered unique id by using a nanosecond
timestamp, but doesn't take into account that time is not monotonic
increasing. This provides an implementation that will always be
increasing.
@jbardin jbardin merged commit 24ebb72 into master Nov 21, 2016
@jbardin jbardin deleted the jbardin/unique-id branch November 21, 2016 14:13
@glasser
Copy link
Contributor

glasser commented Jun 13, 2017

I know this was a while ago, but I only noticed it recently.

The goal of introducing the timestamp (see #8143 and #8249) was less about getting ordering between resources created in a single invocation of terraform, and more about ordering between resources created by different invocations.

For example, when creating a new AWS ASG and moving instances slowly from the old one to the new one, I wanted to be able to easily see "this is the old one, this is the new one". It also makes it immediately obvious "I made this ASG about two weeks ago" which is helpful.

So we've moved from "purely random" to "mostly ordered and indicates the general time when something started, with random prefix" to "consistent within a single TF iteration but otherwise not helpful".

Would you accept a PR that restored the timestamp prefix but with an incrementing suffix?

glasser added a commit to meteor/terraform that referenced this pull request Jun 13, 2017
The timestamp prefix added in hashicorp#8249 was removed in hashicorp#10152 to ensure that
returned IDs really are properly ordered.  However, this meant that IDs were no
longer ordered over multiple invocations of terraform, which was the main
motivation for adding the timestamp in the first place.  This commit does a
hybrid: timestamp-plus-incrementing-counter instead of just incrementing counter
or timestamp-plus-random.
@glasser
Copy link
Contributor

glasser commented Jun 13, 2017

@jbardin see #15280

glasser added a commit to meteor/terraform that referenced this pull request Jun 13, 2017
The timestamp prefix added in hashicorp#8249 was removed in hashicorp#10152 to ensure that
returned IDs really are properly ordered.  However, this meant that IDs were no
longer ordered over multiple invocations of terraform, which was the main
motivation for adding the timestamp in the first place.  This commit does a
hybrid: timestamp-plus-incrementing-counter instead of just incrementing counter
or timestamp-plus-random.
glasser added a commit to meteor/terraform that referenced this pull request Jun 13, 2017
The timestamp prefix added in hashicorp#8249 was removed in hashicorp#10152 to ensure that
returned IDs really are properly ordered.  However, this meant that IDs were no
longer ordered over multiple invocations of terraform, which was the main
motivation for adding the timestamp in the first place.  This commit does a
hybrid: timestamp-plus-incrementing-counter instead of just incrementing counter
or timestamp-plus-random.
glasser added a commit to meteor/terraform that referenced this pull request Jun 15, 2017
The timestamp prefix added in hashicorp#8249 was removed in hashicorp#10152 to ensure that
returned IDs really are properly ordered.  However, this meant that IDs were no
longer ordered over multiple invocations of terraform, which was the main
motivation for adding the timestamp in the first place.  This commit does a
hybrid: timestamp-plus-incrementing-counter instead of just incrementing counter
or timestamp-plus-random.
glasser added a commit to meteor/terraform that referenced this pull request Jun 15, 2017
The timestamp prefix added in hashicorp#8249 was removed in hashicorp#10152 to ensure that
returned IDs really are properly ordered.  However, this meant that IDs were no
longer ordered over multiple invocations of terraform, which was the main
motivation for adding the timestamp in the first place.  This commit does a
hybrid: timestamp-plus-incrementing-counter instead of just incrementing counter
or timestamp-plus-random.
glasser added a commit to meteor/terraform that referenced this pull request Jun 15, 2017
The timestamp prefix added in hashicorp#8249 was removed in hashicorp#10152 to ensure that
returned IDs really are properly ordered.  However, this meant that IDs were no
longer ordered over multiple invocations of terraform, which was the main
motivation for adding the timestamp in the first place.  This commit does a
hybrid: timestamp-plus-incrementing-counter instead of just incrementing counter
or timestamp-plus-random.
@ghost
Copy link

ghost commented Apr 9, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants