feat(batch27): implement jetstream engine state and account enable core
This commit is contained in:
@@ -424,4 +424,79 @@ public sealed partial class NatsServer
|
||||
var js = _jetStream;
|
||||
return js != null && Interlocked.CompareExchange(ref js.Disabled, 0, 0) == 0;
|
||||
}
|
||||
|
||||
public bool JetStreamEnabledForDomain()
|
||||
{
|
||||
if (JetStreamEnabled())
|
||||
return true;
|
||||
|
||||
foreach (var value in _nodeToInfo.Values)
|
||||
{
|
||||
if (value is NodeInfo { Js: true })
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public JetStreamConfig? JetStreamConfig()
|
||||
{
|
||||
var js = _jetStream;
|
||||
if (js == null)
|
||||
return null;
|
||||
|
||||
var cfg = js.Config;
|
||||
return new JetStreamConfig
|
||||
{
|
||||
MaxMemory = cfg.MaxMemory,
|
||||
MaxStore = cfg.MaxStore,
|
||||
StoreDir = cfg.StoreDir,
|
||||
SyncInterval = cfg.SyncInterval,
|
||||
SyncAlways = cfg.SyncAlways,
|
||||
Domain = cfg.Domain,
|
||||
CompressOK = cfg.CompressOK,
|
||||
UniqueTag = cfg.UniqueTag,
|
||||
Strict = cfg.Strict,
|
||||
};
|
||||
}
|
||||
|
||||
public string StoreDir()
|
||||
{
|
||||
var js = _jetStream;
|
||||
return js == null ? string.Empty : js.Config.StoreDir;
|
||||
}
|
||||
|
||||
public int JetStreamNumAccounts()
|
||||
{
|
||||
var js = _jetStream;
|
||||
if (js == null)
|
||||
return 0;
|
||||
|
||||
js.Lock.EnterReadLock();
|
||||
try
|
||||
{
|
||||
return js.Accounts.Count;
|
||||
}
|
||||
finally
|
||||
{
|
||||
js.Lock.ExitReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
public (long MemReserved, long StoreReserved, Exception? Error) JetStreamReservedResources()
|
||||
{
|
||||
var js = _jetStream;
|
||||
if (js == null)
|
||||
return (-1, -1, new InvalidOperationException("jetstream not enabled"));
|
||||
|
||||
return (
|
||||
Interlocked.Read(ref js.MemReserved),
|
||||
Interlocked.Read(ref js.StoreReserved),
|
||||
null);
|
||||
}
|
||||
|
||||
internal JetStreamEngine? GetJetStream() =>
|
||||
_jetStream == null ? null : new JetStreamEngine(_jetStream);
|
||||
|
||||
internal JetStream? GetJetStreamState() => _jetStream;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user