Commit Graph

2937 Commits

Author SHA1 Message Date
Risto Lahtela
16e6ef1dc7
[#769, #928] Session save on server shutdown (#927)
* ShutdownHook: No sessions to save check

ShutdownHook now checks if it needs to save any sessions and does not
start the database if no sessions are unsaved.

* SessionCache.getActiveSessions() now immutable

* [#769] Bukkit and Sponge server shutdown save

Implemented following save procedure for Bukkit:
- On plugin disable check if server is shutting down and save sessions
- Shutdown hook triggered on JVM shutdown calls the same session save
- Save clears sessions from cache, so the sessions are not saved twice

Implemented following save procedure for Sponge:
- Listen for GameStoppingServerEvent
- On plugin disable ask listener if shutting down and save sessions
- Shutdown hook triggered on JVM shutdown calls the same session save
- Save clears sessions from cache, so the sessions are not saved twice

Test:
- Tests ShutdownSave on reload
- Tests ShutdownSave on shutdown
- Tests ShutdownSave on JVM shutdown
2019-02-24 12:28:58 +02:00
Risto Lahtela
96564c90be
[Merge] [#818] Organized Database Classes (#920)
These can be summarized in 3 categories of changes:

### Moved SQL queries from `Table` classes to `Queries` classes.

`Table` classes were turned into static information classes that only contain statements and table fields for the tables. Classes with static methods were created that return `Query<T>` objects that can be passed to the Database. This simplifies addition of multi-table queries.

### Changes are now executed via Transactions

A new `Transaction` class was made, and executing row updating statements was limited inside these classes. This allows committing changes once per multiple statements (speedup) and rolling back partial failed transactions (reliability).

### Database ExecutorService and access lock

A single thread executor was added to be in charge of executing Transactions. All submitted transactions will be executed by this one thread.
Queries will be held until database is operational (Patches have been applied). This should alleviate issues such as #893

## Other changes

- SaveOperations, CheckOperations, CountOperations, SearchOperations were all removed. FetchOperations was completely deprecated, but since it is still provided by `PlanAPI` it was kept in place.
`FetchOperations` is scheduled for removal upon implementation of the new PluginData API.

- Database interface was not very useful, so it was changed to make it usable instead of SQLDB.

- [Wrong branch] Moved to using JUnit 5.4 TempDir instead of junitpioneer 

- `DataCache` was split off to a separate class `NicknameCache` and `SessionCache` no longer saves the session when ended, responsibility is now with the caller
2019-02-22 10:49:58 +02:00
Rsl1122
871fa9b979 Added a fail message to web traffic if database is not open 2019-02-22 10:35:36 +02:00
Rsl1122
ac7093237e Added a fail message to commands if database is not open 2019-02-22 10:17:27 +02:00
Rsl1122
8caa8350ca Fix nickname cache call blocking server thread 2019-02-21 21:25:27 +02:00
Risto Lahtela
82fbbb5209
Merge branch 'development' into db-refactoring 2019-02-19 17:45:24 +02:00
dependabot[bot]
97ef1e39ce
Bump mockito-core from 2.24.0 to 2.24.5 in /Plan (#925) 2019-02-19 15:43:50 +00:00
dependabot[bot]
1589a89a6b
Bump slf4jVersion from 1.7.25 to 1.7.26 in /Plan (#924) 2019-02-19 15:24:26 +00:00
dependabot[bot]
28940f3ef7
Bump mockito-junit-jupiter from 2.24.0 to 2.24.5 in /Plan (#923) 2019-02-19 15:23:41 +00:00
Rsl1122
4e65f99228 Added missing license header 2019-02-19 13:01:17 +02:00
Rsl1122
1e87145767 Fixed sonar smells:
Level major:
- Specified exception in ServerServerInfo

Level minor:
- Unnecessary parentheses removed in BukkitUserImportRefiner

Level info:
- Removed DataCache
- Finished a todo in H2DB
2019-02-19 12:56:12 +02:00
Rsl1122
ee50ebde2c Removed ExecStatement#executeBatch, ExecBatchStatement should be used. 2019-02-19 12:52:27 +02:00
Rsl1122
4f63a3771b Refactored database clean task out of the database
Fixed SonarCloud smells:

Level blocker:
- Removed 'dbType' field from CreateIndexTransaction (is in Transaction)
- Removed unused 'dbSystem' from AnalysisContainer
2019-02-19 12:51:52 +02:00
Rsl1122
0d8c2f2824 Removed ProxySessionCache:
This class is no longer required since responsibility of storage of
sessions now lies with the caller and it's functionality can be
achieved by not saving the returned optional.
2019-02-19 12:36:13 +02:00
Rsl1122
a41a4683c6 Removed Column interface, not used:
- Removed TableSqlParser, not used
- Removed Select#from that used Column
- Removed Update#values that used Column
- Removed Insert#values that used Column
2019-02-19 12:32:11 +02:00
Rsl1122
000290bb24 Bump pluginbridge version to 4.7.0 2019-02-19 12:22:30 +02:00
Rsl1122
530c4a2ea6 Fixed pluginbridge
- AAC SQL stuff
- ViaVersion & ProtocolSupport SQL stuff
- Litebans SQL stuff
- PlaceholderAPIHook (unfinished) SQL stuff
- Towny & Vault DataCache stuff
- Removed since javadoc tags
- Bridge Version bump to 4.7.0
2019-02-19 12:21:07 +02:00
Rsl1122
acae1c4b3d Removed DBInitException throws clauses from methods 2019-02-18 18:21:14 +02:00
Rsl1122
0b7b0a5a16 Removed DBException:
- Made DBInitException subclass of DBOpException
2019-02-18 18:15:50 +02:00
Rsl1122
6fbd8ced60 Fixed concurrency issues with backup related commands 2019-02-18 18:03:09 +02:00
Rsl1122
e1bef920e7 Fixed connection system auth query 2019-02-18 17:59:02 +02:00
Rsl1122
8f3f2e9127 Fixed a network page query 2019-02-18 17:57:38 +02:00
Rsl1122
bbb158ddc5 Fixed peak TPS query 2019-02-18 17:20:04 +02:00
Rsl1122
c60003cda0 Made db field in Transaction private 2019-02-17 23:06:43 +02:00
Rsl1122
e2310e4376 Fixed Patch code failing if a table doesn't exist 2019-02-17 22:57:37 +02:00
Rsl1122
1378d3100e Transaction rollback fail no longer hides original exception 2019-02-17 22:52:30 +02:00
Rsl1122
8870e034e1 All database transactions are now performed by a single thread.
- Added a Database Access Lock object
  - Access log lets OperationCriticalTransactions through
  - Transactions skip query access log check
  - executeTransaction returns a Future to allow easier synchronization
  - ServerInfo waits for the server to be registered. This could lead
    to issues if a new server is registering to old database. It should
    not be too big of an issue since no patches need to be applied
    on first enable of the database.
- Added database states: CLOSED <-> INITIALIZING -> OPEN -> CLOSED

These two changes allow restricting queries to the database until the
database has properly initialized (Schema is in correct format)

- Removed SQLDB as a Patch class variable

Tests use Guava direct thread executor on the database to reduce
concurrency issues during tests. Another option would be to wait for
each transaction.
2019-02-16 20:26:08 +02:00
Rsl1122
2b9e407816 Removed sql Table class 2019-02-16 15:14:20 +02:00
Rsl1122
360e631fc9 Removed PatchTask 2019-02-16 14:58:54 +02:00
Rsl1122
33eec6d990 Moved to using JUnit 5.4 TempDir instead of junitpioneer 2019-02-16 14:55:00 +02:00
Rsl1122
039696910c Removed ProxyAPI and ServerAPI since implementations are the same 2019-02-16 14:48:36 +02:00
Rsl1122
23969192c1 Moved two peak player count queries to TPSQueries class 2019-02-16 14:29:28 +02:00
Rsl1122
f83be34f09 Deprecation javadoc messages to FetchOperations 2019-02-16 14:29:27 +02:00
Rsl1122
738a58edc2 Removed SQLErrorUtil 2019-02-16 14:29:26 +02:00
Rsl1122
328e42a19b Removed Database#fetch usage 2019-02-16 14:29:26 +02:00
Rsl1122
f77750c138 Removed SQLOps class 2019-02-16 14:29:25 +02:00
Rsl1122
463f56f340 TPSTable now static information class:
- Made constructor private
- Removed getter in SQLDB
2019-02-16 14:29:24 +02:00
Rsl1122
ba41952bee Refactored TPSTable#getPlayersOnlineForServers to a query 2019-02-16 14:29:23 +02:00
Rsl1122
6eafce05ba Removed TPSTable#getNetworkOnlineData - not used 2019-02-16 14:29:23 +02:00
Rsl1122
9f1479a65c Refactored TPSTable#getTPSData to a query 2019-02-16 14:29:22 +02:00
Rsl1122
fcdc281219 UserInfoTable is now static information class:
- Made constructor private
- Removed getter in SQLDB
2019-02-16 14:29:21 +02:00
Rsl1122
0c893ea59c Ban and Operator status Transactions:
- Removed SaveOperations
- Removed BanAndOpProcessor, PlayerProcessors
- Removed UserInfoTable#updateOpStatus, UserInfoTable#updateBanStatus
2019-02-16 14:29:20 +02:00
Rsl1122
57695d6e43 Created SessionEndTransaction:
- Removed SaveOperations#session
- Removed DBSystem dependency from SessionCache, so SessionCache does
  not need to be called from async thread. (SessionCache does not save,
  responsibility now with the caller)
2019-02-16 14:29:19 +02:00
Rsl1122
40a62874a3 Created ServerShutdownTransaction 2019-02-16 14:29:18 +02:00
Rsl1122
11369fe62d Fix syntax error in UserIdentifierQueries 2019-02-16 14:29:17 +02:00
Rsl1122
81b9925057 UsersTable now a static information class:
- Made constructor private
- Removed getter in SQLDB
2019-02-16 14:29:17 +02:00
Rsl1122
70e83a12b4 Refactored UsersTable#kicked to a transaction 2019-02-16 14:29:16 +02:00
Rsl1122
4c235b95e2 Refactored UsersTable#getMatchingNames to a query:
- Removed SearchOperations
2019-02-16 14:29:15 +02:00
Rsl1122
de7a1b3286 Refactored UsersTable#getPlayerName to a query 2019-02-16 14:29:14 +02:00
Rsl1122
57f7cb710a Split identifier (UUID, name) related queries to own class. 2019-02-16 14:29:13 +02:00