Skip to content

Commit fa319d7

Browse files
authored
smp server: remove empty journals when opening message queue (#1456)
* smp server: remove empty journals when opening message queue * update, do not backup state * test * version * do not close queue state when queue is opened for writing * comment * quota = 4 * refactor openMsgQueue to prevent extra state backups * use interval in config * version, expire backups after 5 min * refactor * test
1 parent c192339 commit fa319d7

File tree

10 files changed

+280
-88
lines changed

10 files changed

+280
-88
lines changed

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ packages: .
44
-- packages: . ../http2
55
-- packages: . ../network-transport
66

7+
-- uncomment two sections below to run tests with coverage
78
-- package *
89
-- coverage: True
910
-- library-coverage: True

simplexmq.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ test-suite simplexmq-test
457457
apps/smp-server/web
458458
default-extensions:
459459
StrictData
460+
-- add -fhpc to ghc-options to run tests with coverage
460461
ghc-options: -Weverything -Wno-missing-exported-signatures -Wno-missing-import-lists -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-missing-local-signatures -Wno-missing-kind-signatures -Wno-missing-deriving-strategies -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-implicit-prelude -Wno-missing-safe-haskell-mode -Wno-missing-export-lists -Wno-partial-fields -Wcompat -Werror=incomplete-record-updates -Werror=incomplete-patterns -Werror=incomplete-uni-patterns -Werror=missing-methods -Werror=tabs -Wredundant-constraints -Wincomplete-record-updates -Wunused-type-patterns -O2 -threaded -rtsopts -with-rtsopts=-A64M -with-rtsopts=-N1
461462
build-depends:
462463
base

src/Simplex/Messaging/Server/Env/STM.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Data.List (intercalate)
2525
import Data.List.NonEmpty (NonEmpty)
2626
import Data.Maybe (isJust, isNothing)
2727
import qualified Data.Text as T
28-
import Data.Time.Clock (getCurrentTime)
28+
import Data.Time.Clock (getCurrentTime, nominalDay)
2929
import Data.Time.Clock.System (SystemTime)
3030
import qualified Data.X509 as X
3131
import Data.X509.Validation (Fingerprint (..))
@@ -297,8 +297,8 @@ newEnv config@ServerConfig {smpCredentials, httpCredentials, storeLogFile, msgSt
297297
msgStore@(AMS _ store) <- case msgStoreType of
298298
AMSType SMSMemory -> AMS SMSMemory <$> newMsgStore STMStoreConfig {storePath = storeMsgsFile, quota = msgQueueQuota}
299299
AMSType SMSJournal -> case storeMsgsFile of
300-
Just storePath ->
301-
let cfg = JournalStoreConfig {storePath, quota = msgQueueQuota, pathParts = journalMsgStoreDepth, maxMsgCount = maxJournalMsgCount, maxStateLines = maxJournalStateLines, stateTailSize = defaultStateTailSize, idleInterval = idleQueueInterval}
300+
Just storePath ->
301+
let cfg = mkJournalStoreConfig storePath msgQueueQuota maxJournalMsgCount maxJournalStateLines idleQueueInterval
302302
in AMS SMSJournal <$> newMsgStore cfg
303303
Nothing -> putStrLn "Error: journal msg store require path in [STORE_LOG], restore_messages" >> exitFailure
304304
ntfStore <- NtfStore <$> TM.emptyIO
@@ -357,6 +357,20 @@ newEnv config@ServerConfig {smpCredentials, httpCredentials, storeLogFile, msgSt
357357
| isJust storeMsgsFile = SPMMessages
358358
| otherwise = SPMQueues
359359

360+
mkJournalStoreConfig :: FilePath -> Int -> Int -> Int -> Int64 -> JournalStoreConfig
361+
mkJournalStoreConfig storePath msgQueueQuota maxJournalMsgCount maxJournalStateLines idleQueueInterval =
362+
JournalStoreConfig
363+
{ storePath,
364+
quota = msgQueueQuota,
365+
pathParts = journalMsgStoreDepth,
366+
maxMsgCount = maxJournalMsgCount,
367+
maxStateLines = maxJournalStateLines,
368+
stateTailSize = defaultStateTailSize,
369+
idleInterval = idleQueueInterval,
370+
expireBackupsAfter = 14 * nominalDay,
371+
keepMinBackups = 2
372+
}
373+
360374
newSMPProxyAgent :: SMPClientAgentConfig -> TVar ChaChaDRG -> IO ProxyAgent
361375
newSMPProxyAgent smpAgentCfg random = do
362376
smpAgent <- newSMPClientAgent smpAgentCfg random

src/Simplex/Messaging/Server/Main.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import Simplex.Messaging.Server.CLI
4444
import Simplex.Messaging.Server.Env.STM
4545
import Simplex.Messaging.Server.Expiration
4646
import Simplex.Messaging.Server.Information
47-
import Simplex.Messaging.Server.MsgStore.Journal (JournalStoreConfig (..))
4847
import Simplex.Messaging.Server.MsgStore.Types (AMSType (..), SMSType (..), newMsgStore)
4948
import Simplex.Messaging.Server.QueueStore.STM (readQueueStore)
5049
import Simplex.Messaging.Transport (simplexMQVersion, supportedProxyClientSMPRelayVRange, supportedServerSMPRelayVRange)
@@ -147,7 +146,9 @@ smpServerCLI_ generateSite serveStaticFiles attachStaticFiles cfgPath logPath =
147146
doesFileExist iniFile >>= \case
148147
True -> readIniFile iniFile >>= either exitError a
149148
_ -> exitError $ "Error: server is not initialized (" <> iniFile <> " does not exist).\nRun `" <> executableName <> " init`."
150-
newJournalMsgStore = newMsgStore JournalStoreConfig {storePath = storeMsgsJournalDir, pathParts = journalMsgStoreDepth, quota = defaultMsgQueueQuota, maxMsgCount = defaultMaxJournalMsgCount, maxStateLines = defaultMaxJournalStateLines, stateTailSize = defaultStateTailSize, idleInterval = checkInterval defaultMessageExpiration}
149+
newJournalMsgStore =
150+
let cfg = mkJournalStoreConfig storeMsgsJournalDir defaultMsgQueueQuota defaultMaxJournalMsgCount defaultMaxJournalStateLines $ checkInterval defaultMessageExpiration
151+
in newMsgStore cfg
151152
iniFile = combine cfgPath "smp-server.ini"
152153
serverVersion = "SMP server v" <> simplexMQVersion
153154
defaultServerPorts = "5223,443"

0 commit comments

Comments
 (0)