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 getNextAvailableAddress to use local maximums instead of just last a... #168

Merged
merged 6 commits into from
Jun 23, 2014

Conversation

byxorna
Copy link
Contributor

@byxorna byxorna commented Jun 20, 2014

...ddress

@dallasmarlow @joshrabinowitz @Primer42 @maddalab Comments/reviews welcome. This intends to fix IP allocation when not using pools. Old behavior would just allocate the next address, regardless of if a lower address was free. It would fail to allocate if you had a range 0..20 and IPs 18,19,20 were in use :(

Ive tested this for edgecases, and believe it is working correctly. However, I would love comments. I have a sneaking suspicion I could do this slickly with a for comprehension, but it escapes me.

localMax <- sortedAddresses if !sortedAddresses.contains(localMax + 1)
) yield localMax

localMaximaAddresses.isEmpty match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localMaximaAddresses.headOption.flatMap( localMax => ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah awesome. I knew there had to be something like that, but totally forgot about this method. Thanks, that will clean this up

orderBy(t.address asc)
).toSeq

val localMaximaAddresses = for {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make these lazy

scala> lazy val selection = for { i <- Stream.range(0, x.size-2)
     |   curr = x(i)
     |   next = x(i+1)
     |   if (next > curr + 1)
     | } yield curr
selection: scala.collection.immutable.Stream[Long] = <lazy>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, makes sense.

@yl3w
Copy link
Contributor

yl3w commented Jun 23, 2014

lgtm 6️⃣

@byxorna
Copy link
Contributor Author

byxorna commented Jun 23, 2014

@maddalab updated, and confirmed that it functions correctly now. Could you please take a look and see if everything makes sense?

).toSeq

lazy val localMaximaAddresses = for {
i <- Range(0, sortedAddresses.size-1).inclusive.toStream
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that have to be size - 2? either that or remove the inclusive

scala> x
Array[Int] = Array(1, 2, 3)

scala> Range(0, x.size - 1)
scala.collection.immutable.Range = Range(0, 1)

scala> Range(0, x.size - 1).inclusive
scala.collection.immutable.Range = Range(0, 1, 2)

scala> x.size
Int = 3

scala> x(2)
Int = 3

scala> x(2+1)
java.lang.ArrayIndexOutOfBoundsException: 3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke with gabe. lgtm

@william-richard
Copy link
Contributor

I haven't tested all the edge cases, but a basic test looks like its working.

I can't quite figure out where in the code its going out and finding which addresses are allocated or not - is that what subnetinfo in ipaddresscalc does?
https://github.com/tumblr/collins/blob/gabe-ipmi-ip-wrapping/app/util/IpAddress.scala#L103

@byxorna byxorna changed the title [WIP] fix getNextAvailableAddress to use local maximums instead of just last a... fix getNextAvailableAddress to use local maximums instead of just last a... Jun 23, 2014
@william-richard
Copy link
Contributor

OK @byxorna answered my question offline. LGTM

@yl3w
Copy link
Contributor

yl3w commented Jun 23, 2014

@byxorna :goberserk: 🏁

@byxorna
Copy link
Contributor Author

byxorna commented Jun 23, 2014

📻 📟 📼 🐻

byxorna pushed a commit that referenced this pull request Jun 23, 2014
fix getNextAvailableAddress to use local maximums instead of just last a...
@byxorna byxorna merged commit 57670bd into master Jun 23, 2014
@william-richard william-richard deleted the gabe-ipmi-ip-wrapping branch September 9, 2014 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants