Commit Graph

190 Commits

Author SHA1 Message Date
Spottedleaf
25e0cbdae4 Rework some parts of the player chunk loader
Change overview:
- Rework limiting
- Remove mid tick updates
- Introduce consistency checks

The old limiting logic used an intervalled counter, but
did not account for possible slight changes in mid tick
invoke rate as it relied heavily on mid-tick logic. Due to
the removal of mid tick updates, it is now important that
the logic functions correctly no matter what rate it is invoked
at. The new logic directly tracks the last update time and
allocates an amount based proportional on the rate targetted,
which makes the logic call rate independent.

The removal of mid tick updates is done to eliminate recursive
call risk, and to additionally reduce the lock pressure on the
chunk system by grouping chunk loads onto one part of the tick
rather than spreading it out. The limiting rework should ensure
that this does not negatively affect rates, but it will decrease
the perceived smoothness of chunk generation/loading at low rates.

Introduce more consistency checks such as correct tick thread
and ticking-after-removal checks. Also, perform checks during the player
chunk loader tick to avoid updating potentially removed
players during the tick.
The checks are primarily made to try to hunt down a bug that
is causing the player chunk loader to double send a chunk
to a player.
2023-04-10 17:51:21 -07:00
Spottedleaf
ad70ddfc20 Lag compensate block breaking
Due to TPS catchup being removed, a lost tick will always
affect block breaking.

Additionally, constant low TPS would affect block breaking
in an intrusive manner to the user when there is no need
for that to occur.
2023-04-10 14:16:16 -07:00
Spottedleaf
105f6d6a21 Adjust CB async teleport dismount behavior
The expected behavior is that the entity is only dismounted
_if_ the teleport takes place, not regardless of whether
the teleport takes place.

To adhere to the expected behavior, we need to create a new teleport
flag so that the NMS teleportAsync can perform the dismount.
2023-04-08 19:16:10 -07:00
Spottedleaf
c9ded2de1c Add entity/player/chunk counters to /tps
Required to add some basic hacks to expose a regionstats object
in the TickRegions data class, but this ensures that the retrieval
is thread-safe and could possibly support other data exposure
for async reads.

Additionally, since DecimalFormat is not thread-safe we need
to use ThreadLocals to instantiate them. Change the format
as well to use commas to separate groups of digits when
formatting large numbers so they are easier to read.
For example, 1000 becomes 1,000.
2023-04-08 18:44:37 -07:00
Spottedleaf
4431a66c12 Make CB Entity async teleport dismount entities being teleported
This preserves behavior with the older API that did
dismount the entity before teleporting

Fixes https://github.com/PaperMC/Folia/issues/36
2023-04-08 16:56:30 -07:00
Spottedleaf
d34fb878bb Always send untrack chunk packets
Vanilla inserted the alive check so that dead players
could see the chunks around them, but in Folia we do not
remove dead players so chunks will still load for them.

This prevents the client from having chunks in memory it
should not.
2023-04-03 22:50:00 -07:00
Spottedleaf
774141dfb1 Fix mob entity inventory loss when switching dimensions
The inventory was being cleared by removing the entity
from the world, but Folia changed the remove to be
before the entity copy which caused the new entity
to have a cleared inventory. Fix this by creating
a post-dimension copy callback that will clear
the inventory of the old entity.

Fixes https://github.com/PaperMC/Folia/issues/29
2023-04-03 22:14:42 -07:00
Spottedleaf
445613b931 Note world as well when a region fails to tick or execute tasks
Should always include the world if we're including the center
position
2023-04-03 21:26:19 -07:00
Spottedleaf
f8a17538e6 Fix destroying beehive without any players nearby throwing an exception
If the player moves out of range by the time the block is destroyed,
then the exception would throw and remove the player from the world

Additionally, when players fail to tick instead of removing
the player from the world, kick them to prevent a limbo state
2023-04-03 21:26:16 -07:00
Spottedleaf
4b0c614847 Calculate correct redstone offset when merging regions
It should be offset = to - from, not from - to. This should
fix redstone freezing randomly when merging regions.

Fixes https://github.com/PaperMC/Folia/issues/35
2023-04-03 19:33:42 -07:00
Spottedleaf
6d18e8e9b6 Make uses of SimpleDateFormat thread-safe
Turns out, the utility is not thread-safe to use for whatever
reason. So, we need to use ThreadLocal to create instances
per thread.
2023-04-03 18:41:09 -07:00
Spottedleaf
33d2aa8cf7 Make sign update executor use the EntityScheduler
The MinecraftServer executor will throw, and thanks
to CompletableFuture's awful exception handling
the exception was not logged or handled. Add
exception handling as well.

Fixes https://github.com/PaperMC/Folia/issues/27
2023-04-01 07:24:36 -07:00
Spottedleaf
7072994557 Acquire scheduling lock in NewChunkHolder#onFullChunkLoadChange
It modifies data that should be held by the lock: pending
chunk status
2023-04-01 00:53:27 -07:00
Spottedleaf
700d3c580c Always process specialCaseUnload during ticket level updates
It is not guaranteed that ticket levels are updated, so we need to
to move the logic so that it always runs whether or not tickets
update.
2023-03-31 21:20:53 -07:00
Spottedleaf
76b06a1260 Do not call getGameTime when portalling Villagers
The code to stop all brain tasks is required to pass the current
game time to the tasks it stops. But, when a villager is being
portalled, the copied entity does not have any running tasks. So,
we can simply return early before invoking getGameTime if there
are no running tasks.

Fixes https://github.com/PaperMC/Folia/issues/23
2023-03-31 20:48:20 -07:00
Spottedleaf
3f377072d8 Make move event location update use teleportAsync
Additionally, make the teleportAsync call immediately teleport
if the current caller owns the entity.

Fixes https://github.com/PaperMC/Folia/issues/18
2023-03-31 19:13:19 -07:00
Jake Potrebic
9c8863a490
Fix enchant command feedback messages (#22)
* Fix enchant command feedback messages
2023-03-31 18:25:55 -07:00
Jake Potrebic
508a6688e5
Fix 2 incorrect threading checks (#17)
* Fix 2 incorrect threading checks

* Fix bad catcher methods, fix missing async catcher

---------

Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
2023-03-31 17:15:16 -07:00
Jason
fbf832bc05
Log traces of tick threads that fail to shut down (#10)
* Log traces of threads that fail to shut down in SchedulerThreadPool
2023-03-31 16:51:55 -07:00
Noah van der Aa
ed7a5c57f4
fix: fix build number check in version fetcher (#16) 2023-03-30 14:13:55 -07:00
Riley Park
00864ac5b1 Update Upstream (PaperMC/Paper@cbcdfd03e7) 2023-03-29 19:41:15 -07:00
Spottedleaf
f34a20c36a Fix incorrect error handling in off-main chunk load task
Now that there is no on-main task, the completion logic
for the status task is completed with the results passed
by the off-main task. Thus, the chunk system saw a non-null
throwable and assumed a fatal crash. The old on-main task
did not pass the throwable through in this case, which allowed
the chunk to re-generate.

Fixes https://github.com/PaperMC/Folia/issues/7
2023-03-29 17:11:39 -07:00
Spottedleaf
749480c7ec Fix getCenterChunk not returning the center chunk
Before, it returned the center chunk section. Also, now instead
of approximating the center chunk from the allocated sections,
actually retrieve all chunks inside the region directly.
2023-03-29 16:58:33 -07:00
Spottedleaf
b3e1b06c07 Fix compilation of TestPluginMeta
Needed to implement isFoliaSupported()
2023-03-29 14:33:48 -07:00
Spottedleaf
9998ecd60d Make ActivationRange#activateEntities use non-checked getEntities
We can do this because we thread-check the entities retrieved,
we want to do this because a large activation range may violate
thread-checks
2023-03-29 14:22:15 -07:00
Owen1212055
32f79c415e Support paper plugin meta marking plugins as Folia supported 2023-03-29 14:12:30 -07:00
Spottedleaf
f42c61aba6 Folia Metrics page
https://bstats.org/plugin/server-implementation/Folia/18084
2023-03-29 12:53:55 -07:00
Jason Penilla
fca2eba2f8
fix build 2023-03-29 10:18:38 -07:00
Spottedleaf
7de5c541b3 Nerf default tick thread allocation
Allocates too many threads by default
2023-03-29 08:12:27 -07:00
Josh Roy
88167d59d2
Add Server#isGlobalTickThread (#5) 2023-03-28 18:59:19 -07:00
Spottedleaf
108dc2358b Use chunk coords for thread check for CraftWorld#getHighestBlockYAt
Not block coords
2023-03-28 16:13:18 -07:00
Spottedleaf
1c5e9be7fd Force prevent moving into unloaded chunks
Not safe to allow this anymore
2023-03-28 15:59:41 -07:00
Spottedleaf
d113346b6d Fix isTickThread(world, blockX, blockZ)
Need to convert the Z to chunk, not block...

Also throw for CraftPlayer#teleport and friends
2023-03-27 20:29:16 -07:00
Spottedleaf
1175350400 Fix failure to initialise CraftWorld
Directly access spawn category limits rather than go through
the method
2023-03-27 16:06:19 -07:00
Josh Roy
5fa0556869
Use longs for scheduler delays/periods (#4) 2023-03-25 21:48:28 -07:00
Spottedleaf
75e3cdbc61 Rebase fixups 2023-03-25 16:29:07 -07:00
Spottedleaf
66c77fb573 Add more thread checks to API
Most of the World methods, and for updating captured TEs
2023-03-25 16:26:54 -07:00
Spottedleaf
c435aaae96 Add world checks to retrieval of regionised world data
This is to mirror behavior of RegionizedData's world check.
2023-03-25 15:27:50 -07:00
Spottedleaf
7eea12b9e4 Kenny momentos
Random newline?
2023-03-25 11:55:44 -07:00
Nassim Jahnke
3c62932250
Fix player disconnect call in PlayerList removAll 2023-03-25 19:44:11 +01:00
Nassim Jahnke
5e7b4f0185
Fix tests by removing them 2023-03-25 19:06:35 +01:00
Nassim Jahnke
836dc75b65
Replace Vector with Position in isOwnedByCurrentRegion methods
Closes #3
2023-03-25 18:50:36 +01:00
Nassim Jahnke
8d15f3e23d
Add methods taking world, chunkX, chunkZ to RegionScheduler 2023-03-25 18:40:20 +01:00
Nassim Jahnke
dfc157075a
Renames for consistency 2023-03-25 00:22:47 +01:00
Spottedleaf
6a5fff3caa Make ClickCallbackProviderImpl thread-safe
Can no longer process tasks from the main thread like that anymore,
it just needs to be concurrent.
2023-03-23 07:55:26 -07:00
Spottedleaf
d5b837c457 Make Damagecommand safe, and remove RideCommand 2023-03-23 07:36:44 -07:00
Spottedleaf
4c183bf960 Fix compile 2023-03-23 07:22:57 -07:00
Spottedleaf
c7fbdd87d2 Update to 1.19.4
Patches applied, but not yet checked compile.
2023-03-23 06:55:09 -07:00
Spottedleaf
e3a299c5ce Lowercase project names
Make JMP happy
2023-03-23 04:53:58 -07:00
Spottedleaf
50ad6c3131 New scheduler API
Now, entity/global/location schedulers implement a generic run,
runDelayed, and runAtFixedRate methods that provide a ScheduledTask
value that can be used to interact with the scheduled task.

Add also an async task scheduler that implements the same methods,
except the delays/periods are in time and not ticks, as the scheduler
is independent of the server tick process.

Additionally, throw on some unimplemented APIs now.
2023-03-23 02:51:04 -07:00
Spottedleaf
0da953539b Disable mid-tick task execution
Mid-tick task execution acquires the ticket lock at least,
which can possibly be a significant performance bottleneck
at a high tick thread + region count. This change should reduce
the impact from scaling the region threads, but is not a fix
to the underlying issue.
2023-03-20 02:48:16 -07:00
Spottedleaf
106a4affdc Suppress entire CB passenger events if the entity is not valid
The event is not being called, so the checks will not do
anything. We need to bypass the checks so that we do not trip
the thread check.
2023-03-19 17:41:24 -07:00
Spottedleaf
7e948a6179 Add global region scheduler
This will allow plugins to safely execute commands or perform
other global tick thread data modification.
2023-03-19 16:43:34 -07:00
Spottedleaf
cbf8108d4e Make max concurrent logins patch use maxJoinsPerTick config
This patch performed perfectly to handle the test server,
so it can stay.
2023-03-19 14:58:52 -07:00
Spottedleaf
0911c7a58a Remove patches specific for stream
Specifically, the /msg and /me command removal and the operator
only chat. Additionally, remove the TPA commands.
2023-03-19 14:53:06 -07:00
Spottedleaf
ee737050a0 Add thread checks for CraftEntity#getHandle
Also resolve some issues found by this change.

Currently, the player handle checks are disabled.
2023-03-19 14:48:37 -07:00
Spottedleaf
a980944815 Regionise RedStoneWireBlock#shouldSignal
Global state used to update redstone, so it should be regionised.
2023-03-12 20:55:52 -07:00
Spottedleaf
6fe75ab068 Erase mob target in getTarget if it is not in the current region
This will prevent access to the target's position or data.
2023-03-12 15:36:05 -07:00
Spottedleaf
3aeb021748 Make PoiCompetitorScan region-safe
We implement it by ensuring that if the entity is not nearby
the job site, they automatically lose.
2023-03-12 15:25:06 -07:00
Spottedleaf
cf72543628 Rebase fixups 2023-03-12 15:04:00 -07:00
Spottedleaf
a9a885ad00 Resolve concurrent access to ticket state
The concurrent access occurred in the region merge/split logic,
as it did not own the ticket lock. To resolve this, we simply
make the ticket add/remove acquire the read lock of
the region lock.
2023-03-12 15:00:38 -07:00
Spottedleaf
518b2d5dec Fix zero radius tasks being recognized as infinite
Fixes parallelism loss from spawn entity chunk status
2023-03-12 00:51:43 -08:00
Spottedleaf
0a11f6aa1f Do not execute infinite radius task in parallel when pushing tasks
By definition, it should not execute in parallel with anything.
2023-03-12 00:17:44 -08:00
Spottedleaf
3bc5341531 Make specialCaseUnload global state
With region state, it may be modified concurrently while
only holding the region lock. Need to figure out a solution
for the ticket state as well.
2023-03-11 23:28:34 -08:00
Spottedleaf
9561a53e7a Log exceptions in ThreadedRegioniser explicitly
I suspect something called these methods, they threw and then
the error was hidden by some completablefuture somewhere.
2023-03-11 12:56:43 -08:00
Spottedleaf
a80cdafae9 Make uncaught exceptions in tick thread shut down the server 2023-03-11 12:36:37 -08:00
Spottedleaf
3f2b83c35a Make SaplingBlock.treeType a thread-local
Now it is accessed concurrently
2023-03-11 06:27:35 -08:00
Spottedleaf
9e835221b9 Update new bee position before adding to beehive
This will ensure the thread check from discard does not fail
2023-03-11 06:14:05 -08:00
Spottedleaf
760de0a276 Move region center calculation into try-catch
Sometimes a region is empty, but only when the threaded regioniser
crashes. So, it should not prevent shutdown.

Additionally, only remove pending teleports after setting the
current region.
2023-03-11 05:46:20 -08:00
Spottedleaf
0fa5f339f2 Do not allow players to interact with entities outside the current region 2023-03-11 05:38:11 -08:00
Spottedleaf
d2a5acba4a Do not allow players to interact with blocks outside of their region 2023-03-11 05:16:10 -08:00
Spottedleaf
4af9f6c889 Do not allow players to destroy blocks that are not owned 2023-03-11 05:10:34 -08:00
Spottedleaf
4cffea6652 Read cancelled field while holding region lock
This will prevent a race condition where the region is cancelled
and immediately re-scheduled, and where this all happens while
the tick thread is blocking on tryMarkTicking.
2023-03-10 20:46:58 -08:00
Spottedleaf
f6d776697b Fix kicking player when they die on a vehicle with instant respawn
The respawn logic apparently can fire before the death is broadcasted
2023-03-10 20:11:08 -08:00
Spottedleaf
e1ad1b1d91 No longer give everyone access to /tps
Everyone had access to /tps for the private tests, but we cannot
trust everyone to use it responsibly for the public test
(i.e revealing coordinates of all logged in players).
2023-03-10 00:19:40 -08:00
Spottedleaf
d258d32393 Add chunk system throughput counters to /tps 2023-03-10 00:18:12 -08:00
Spottedleaf
8625606b3d Fix crash if player disconnects during login stage 2023-03-09 21:17:18 -08:00
Spottedleaf
a9d01f9b4f Max pending logins
Should help hold the floodgates on launch
2023-03-09 21:04:10 -08:00
Spottedleaf
bbee4310fe Fix fishing rods throwing exceptions
Need to move setOwner after the position update, as the thread-check
will fall back to position
2023-03-09 20:45:32 -08:00
Spottedleaf
5cbf898ca1 Stream mode
Disable chat and /msg and /me for non-ops so that the server is
safe to stream
2023-03-09 20:45:32 -08:00
Spottedleaf
950216171d Do not let projectiles travel into chunks not owned by current region
Otherwise, the thread checks for moving the entity into the new
entity chunk section would throw and cause the projectile to
be deleted.
2023-03-08 20:15:22 -08:00
Spottedleaf
ef515cc6f5 Consider non-owned chunks in entity movement as unloaded
This should prevent entities from moving into areas not owned
by the current region.
2023-03-08 19:44:01 -08:00
Spottedleaf
afd678cab6 Fall back to position check if the entity has a null entity callback
In the case that the entity has a null callback, it means the
entity has not been added to the world - so, we should treat
it the same as entity#isRemoved.
2023-03-08 19:38:50 -08:00
Spottedleaf
deae156e59 Make Level#getBlockEntity return null immediately if not tickthread
Otherwise, the world data will be null and we will NPE. The
function is supposed to return null for off-thread access,
anyways.
2023-03-08 17:40:28 -08:00
Spottedleaf
74f665b6f5 Fix compilation 2023-03-07 20:06:08 -08:00
Spottedleaf
b00a16a66d Fix command label placeholder in usage for /tps
Only <command> gets replaced with the provided label
2023-03-07 17:34:45 -08:00
Spottedleaf
68b20e0acc Add API for checking ownership of region by position/entity
This may be useful for plugins which want to perform operations
over large areas outside of the buffer zone provided by the
regionaliser, as it is not guaranteed that anything outside
of the buffer zone is owned. Then, the plugins may use
the schedulers depending on the result of the ownership
check.
2023-03-07 14:44:37 -08:00
Spottedleaf
386bcd1094 Make ServerLevel#areChunksLoadedForMove also check region ownership
We do not want players to move into chunks that are not owned
by the current region
2023-03-07 13:31:59 -08:00
Spottedleaf
0e4358fb7e Make Player#kickPlayer function asynchronously
We have made disconnect() mt-safe, so there is no need for
this check anymore.
2023-03-07 13:22:53 -08:00
Spottedleaf
7af86e656d Do not schedule keepalive fail kick to main
There is no main thread to schedule to, and I've already
make disconnect() handle off-region kicks safely.
2023-03-07 13:19:29 -08:00
Spottedleaf
99429cee37 Make plugin tickets no longer sync load the chunk
This is to prevent any thread-check from failing. Note that
ticket additions are mt-safe.

Additionally, add more thread checks.
2023-03-07 13:13:31 -08:00
Spottedleaf
2ccfc8efc0 Add RegionisedServerInitEvent
This event allows plugins to perform synchronous operations before
any region will tick. Plugins will not have to worry about the
possibility of a region ticking in parallel while listening
to the event.
2023-03-07 13:06:11 -08:00
Spottedleaf
f86bc13d22 Make tpdeny prompt show /tpadeny instead of /tpaccept
As it should be showing
2023-03-07 13:03:20 -08:00
Spottedleaf
71a4219ab6 Make sure /tps includes global region in total util percent
While we expect the util from the global region to be around 0.0,
it doesn't mean it always will be. So, include it.
2023-03-07 12:51:23 -08:00
Spottedleaf
8fcf959ee3 Fix various World chunk methods
- Add thread check for loadChunk
- Make isChunkGenerated use the region task queue to schedule
  to "main"
- Don't complete async chunk future if not in the owning thread
  for the chunk
2023-03-06 14:27:02 -08:00
Spottedleaf
7ca8feff63 Log delayed world init
Nothing ticks until this is done, so it should be logged.
2023-03-06 14:04:08 -08:00
Spottedleaf
5c4d65efb8 Require plugins to be explicitly marked as Folia supported
Plugins must add "folia-supported: true" to their plugin.yml
otherwise the server will refuse to load them.

Since Folia is a major breakage for plugins, the vast majority
of plugins will not function correctly on Folia. To prevent
user confusion from this, we will refuse to load the plugin
and provide a log indicating why - which will be much
more helpful than some random error log caused by
a breakage.
2023-03-06 14:03:17 -08:00
Spottedleaf
4e7205d401 Change entity scheduler API to use Runnables
The generics pose a problem, and the parameter passed to the
Consumer is not needed in API.

Additionally, stop trying to cancel Bukkit scheduler tasks on
plugin disable as the Bukkit scheduler does not work.
2023-03-06 12:57:29 -08:00
Spottedleaf
490b8f5182 Add logo 2023-03-06 02:43:32 -08:00
Spottedleaf
e6d60da06f Halt chunk systems before saving chunks for all worlds
This is to ensure that chunks are not progressing in other worlds
while saving
2023-03-05 12:51:23 -08:00