Esempio n. 1
0
        public Result Commit()
        {
            lock (Locker)
            {
                Result rc = Initialize();
                if (rc.IsFailure())
                {
                    return(rc);
                }

                rc = EnsureKvDatabaseLoaded(false);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                var mount = new Mounter();

                try
                {
                    rc = mount.Initialize(FsClient, MountName, SpaceId, SaveDataId);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    rc = KvDatabase.WriteDatabaseToFile();
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    string idFilePath = $"{MountName}:/{LastIdFileName}";

                    rc = FsClient.OpenFile(out FileHandle handle, idFilePath, OpenMode.Write);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    bool fileAlreadyClosed = false;

                    try
                    {
                        ulong lastId = LastPublishedId;

                        rc = FsClient.WriteFile(handle, 0, SpanHelpers.AsByteSpan(ref lastId), WriteOption.None);
                        if (rc.IsFailure())
                        {
                            return(rc);
                        }

                        rc = FsClient.FlushFile(handle);
                        if (rc.IsFailure())
                        {
                            return(rc);
                        }

                        FsClient.CloseFile(handle);
                        fileAlreadyClosed = true;

                        return(FsClient.Commit(MountName));
                    }
                    finally
                    {
                        if (!fileAlreadyClosed)
                        {
                            FsClient.CloseFile(handle);
                        }
                    }
                }
                finally
                {
                    mount.Dispose();
                }
            }
        }
Esempio n. 2
0
 protected override Result DoFlush()
 {
     return(FsClient.FlushFile(Handle));
 }