Room File Persistence is not working for 2 zone extensions

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

shahidbits2012
Posts: 6
Joined: 09 Jun 2021, 07:23

Room File Persistence is not working for 2 zone extensions

Postby shahidbits2012 » 09 Jun 2021, 07:42

We are trying to use persist the Room data via Room Persistence API (FILE) using an [article][http://docs2x.smartfoxserver.com/AdvancedTopics/room-persistence-api].

It works fine when we have one Zone with ZoneExtension=MyZoneExtension. But, if we add another zone which also has the same zone extension i.e. MyZoneExtension, we get the following error while initialising the second zone -

com.smartfoxserver.v2.persistence.room.FileRoomStorage.getFileList(FileRoomStorage.java:306) com.smartfoxserver.v2.persistence.room.FileRoomStorage.loadAllRooms(FileRoomStorage.java:121) com.smartfoxserver.v2.persistence.room.FileRoomStorage.loadAllRooms(FileRoomStorage.java:111) com.example.MyExtension.initializeRooms(MyExtension.java:132)
com.example.MyExtension.init(MyExtension.java:114) com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:303) com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:428) com.smartfoxserver.v2.entities.managers.SFSZoneManager.initializeZones(SFSZoneManager.java:239) com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:292) com.smartfoxserver.v2.Main.main(Main.java:13)

Can we please get help in resolving this issue?

Thanks!
Last edited by shahidbits2012 on 11 Jun 2021, 14:09, edited 1 time in total.
User avatar
Lapo
Site Admin
Posts: 22015
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room File Persistence is not working for 2 zone extensions

Postby Lapo » 09 Jun 2021, 10:04

Hi,
can you specify which version of SFS2X you're running?

Also the stack trace is incomplete as there's no error message. Can you please re-post the whole stack trace?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
shahidbits2012
Posts: 6
Joined: 09 Jun 2021, 07:23

Re: Room File Persistence is not working for 2 zone extensions

Postby shahidbits2012 » 09 Jun 2021, 11:52

server version: 2.17.0
remote administration: v3.2.6

It is an NPE thrown at below location -

Class: com.smartfoxserver.v2.persistence.room.FileRoomStorage
Method: getFileList(String groupId)

...
File[] var9 = allFiles; // allFiles is null
int var8 = allFiles.length; // Null Pointer Exception
...

Hope this helps!
User avatar
Lapo
Site Admin
Posts: 22015
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room File Persistence is not working for 2 zone extensions

Postby Lapo » 10 Jun 2021, 06:45

Thanks for the details. We'll test this use case and let you know asap.

Stay tuned.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 22015
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room File Persistence is not working for 2 zone extensions

Postby Lapo » 11 Jun 2021, 07:09

We tested the scenario by instantiating two file-based room storage classes in two different Zones but we didn't encounter any issues.

I'd like to see the init() method in your FitplusExtension to better understand what you're doing

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
shahidbits2012
Posts: 6
Joined: 09 Jun 2021, 07:23

Re: Room File Persistence is not working for 2 zone extensions

Postby shahidbits2012 » 11 Jun 2021, 14:12

Code: Select all

/// init()
    @Override
    public void init() {
        ...
        initializeRooms();
    }

    /// method to initialize rooms, if present
    private void initializeRooms() {

        //Initialize Persistence API
        FileRoomStorageConfig cfg = new FileRoomStorageConfig();
        getParentZone().initRoomPersistence(RoomStorageMode.FILE_STORAGE, cfg);

        // Load all previously stored Rooms
        try {
            List<CreateRoomSettings> allRooms = getParentZone().getRoomPersistenceApi().loadAllRooms();

            // Recreate all Rooms
            for (CreateRoomSettings settings : allRooms) {
                getApi().createRoom(getParentZone(), settings, null, false, null, false, false);
            }
        } catch (SFSStorageException storageErr) {
            trace("Error loading rooms: " + storageErr);
        } catch (SFSCreateRoomException creationErr) {
            trace("Error creating room: " + creationErr);
        }

        Thread thread = new ShutdownHookThread();
        Runtime.getRuntime().addShutdownHook(thread);
    }

    /// Thread to save rooms during extension shutdown
    class ShutdownHookThread extends Thread {

        public void run() {

            try {
                  getParentZone().getRoomPersistenceApi().saveAllRooms();
                  trace("Save game rooms success!");
            } catch (SFSStorageException e) {
                  trace("Error saving rooms: " + e.getMessage());
            }
        }
    }
shahidbits2012
Posts: 6
Joined: 09 Jun 2021, 07:23

Re: Room File Persistence is not working for 2 zone extensions

Postby shahidbits2012 » 11 Jun 2021, 23:19

Also, can you try testing with just single class and use the same extension class as the zone extension for both the Zones in admin panel.
User avatar
Lapo
Site Admin
Posts: 22015
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Room File Persistence is not working for 2 zone extensions

Postby Lapo » 12 Jun 2021, 08:02

Hi,
we have done a few more tests and found an issue that only manifests the first time you run this code. From the second time it doesn't happen anymore.

The reason for this is: the first time you initialize the Room Storage for a specific Zone a new folder must be created under data/roomData.
Here we found a bug that doesn't check for the existence of this folder and causes the exception you have reported. However the folder is created a bit later and the next time you restart the exception the error will not appear.

This problem happens regardless of the number of Zones that use the Room Storage and in fact it manifests also when using it with a single Zone.
We have already fixed the problem in our codebase, but we'll probably publish the update a bit later when we have more fixes and updates to release. The workaround for this problem is to simply let it fail the first time and it won't appear from the next restart.

If you want we can also send a custom update for this issue if it is particularly critical for you. In this case please contact us via the support@... email box with a reference to this post.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 48 guests