0

Before I start, I want to say that this is related to a Bukkit plugin.

I have tried searching this all over the web, but I can't just find a good way to do it.

I am trying to build a plugin that can connect to a database (usually MySQL), and locally keep track of the time of the database, even if it goes down. The plugin is a ban management system, for multiple servers. The situation is this one: The timezone of the database server is different from the time on the servers, and each server has its own timezone. There's only 1 database, so, the best way to do it is keeping track of the time using the time of the database. But, if the database goes down, a thread will run until the database comes back and the record is successfully inserted. If I were to use UNIX_TIMESTAMP() on the column that stores when the ban was created, if the database went down, it would only start counting after the database came back. So, breaking it down, what I want is a way to keep track of the time of the database, even if the database goes down and comes back up.

Thanks in advance.

D4rKDeagle
  • 39
  • 2
  • Are you saying you already know how to get the time off the database, and your real question is how to get a best guess of the database time, even when it is down? – Darius X. Dec 09 '13 at 21:15
  • Yes, that's why I'm trying to do. Sorry for the late answer. – D4rKDeagle Dec 18 '13 at 20:49
  • In the class that looks up the date, each time you get the date, you can also figure out your system time (i.e. just the current time reported by the JVM) and compute how many seconds it is different. (It really should not be very different when expressed as the same time-zone.) Then, if your database is offline, you can return the time from the JVM, adjusted by the saved difference. It does seem a bit odd to be using a database simply as a time-server. And, if you are using it for more than that, then you probably have bigger issues when it comes to reading/writing data. – Darius X. Dec 18 '13 at 23:22
  • Because all of the servers have different timezones, I want to use the database time, because that one will not change, unless the host server for the database changes. The database is indeed also being used to store the bans, and storing the dates of the bans using the time in the database seems like the logical thing for me, but yes, it is a bit odd. Anyway, I've already done it: when the plugin first connects to the database, it schedules a task to be executed each second where it has a variable storing the database time, and increasing it each time the task executes. Thanks anyway! – D4rKDeagle Dec 19 '13 at 16:20

1 Answers1

0

Insert the time as calculated by the program (when the event really happened, not when the db "eventually" inserted the data) in UTC. It should be more or less the same regardless of the servers. There could be a slight difference based on clock differences but you can minimize that via ntp to keep the servers' times synchronized.

Community
  • 1
  • 1
Carlos N
  • 1,616
  • 14
  • 15