-
Notifications
You must be signed in to change notification settings - Fork 28
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
Update ConnectionProvider to support AWS writer failovers #113
Update ConnectionProvider to support AWS writer failovers #113
Conversation
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
4aea4e8
to
81e2fb2
Compare
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
testConn = connectionPool.getConnection() | ||
} catch { | ||
case _: SQLTransientConnectionException => { TimeUnit.MILLISECONDS.sleep(100) } // do nothing | ||
case e: Exception => throw e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary. If you don't catch an excetpion in a catch block it will automatically get rethrown
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor feedback around how to handle options
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
worker/src/main/scala/com/lucidchart/piezo/ConnectionProvider.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we need to fix the synchronization issue before merging.
725a4d9
to
4ec9ad4
Compare
size > 1 | ||
} | ||
}) | ||
// TODO: override "removeEldestEntry" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can revome this now right?
private val cachedIpWithExpiration: java.util.Map[String, CachedIpWithExpiration] = Collections.synchronizedMap(new LinkedHashMap[String, CachedIpWithExpiration]() { | ||
// There is only 1 element to be stored in this list at a time, so we remove the oldest entries once we reach 2+ entries | ||
override def removeEldestEntry(eldest: java.util.Map.Entry[String, CachedIpWithExpiration]): Boolean = { | ||
size > 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait.... if we only have 1 entry, maybe it would be simpler just to have a variable for this (synchronized, or maybe @volatile?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah probably simpler to do make is a single optional object. I think @volatile
should be adequate over using synchronized
since as long as there is a cached entry to use, we shouldn't care about whether another thread tried to enter the new or old DNS result into the cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, perhaps synchronized
may be better here. It just makes the cache more reliable if there isn't a race-condition between which IP value is set for the DNS cache
4ec9ad4
to
89bb6a6
Compare
89bb6a6
to
10e041e
Compare
10e041e
to
c571102
Compare
No description provided.