Skip to content

Commit

Permalink
Misc fixes #406 - Issues 1,2,4,7 (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc authored May 22, 2024
1 parent 95149fa commit eab149e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
24 changes: 7 additions & 17 deletions libs/common/Logging/FileLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public static ILoggingBuilder AddFile(
/// </summary>
public class FileLoggerOutput : IDisposable
{
private StreamWriter streamWriter;
private readonly object lockObj = new object();
private readonly TimeSpan flushInterval = Debugger.IsAttached ? TimeSpan.FromMilliseconds(10) : TimeSpan.FromMilliseconds(10);
private DateTime lastFlush = DateTime.UtcNow;
private readonly StreamWriter streamWriter;
private readonly object lockObj;

/// <summary>
/// Create a file logger output
Expand All @@ -50,18 +48,16 @@ public class FileLoggerOutput : IDisposable
/// <param name="flushInterval"></param>
public FileLoggerOutput(string filename, int flushInterval = default)
{
this.flushInterval = flushInterval == default ?
Debugger.IsAttached ? TimeSpan.FromMilliseconds(10) : TimeSpan.FromSeconds(1) :
TimeSpan.FromMilliseconds(flushInterval);
streamWriter = new StreamWriter(File.Open(filename, FileMode.Append, FileAccess.Write, FileShare.ReadWrite), Encoding.UTF8);
lockObj = new object();
}

/// <summary>
/// Dispose FileLoggerOutput
/// </summary>
public void Dispose()
{
streamWriter?.Dispose();
streamWriter.Dispose();
}

/// <summary>
Expand All @@ -84,16 +80,10 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
categoryName,
formatter(state, exception));

lock (this.lockObj)
lock (lockObj)
{
streamWriter?.WriteLine(msg);

//var now = DateTime.UtcNow;
//if(now - lastFlush > flushInterval)
{
//lastFlush = now;
streamWriter.Flush();
}
streamWriter.WriteLine(msg);
streamWriter.Flush();
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions libs/server/Custom/CustomCommandManagerSession.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using Garnet.common;

namespace Garnet.server
{
/// <summary>
Expand All @@ -21,8 +23,18 @@ public CustomCommandManagerSession(CustomCommandManager customCommandManager)
{
if (sessionTransactionProcMap[id].Item1 == null)
{
var entry = customCommandManager.transactionProcMap[id];
sessionTransactionProcMap[id].Item1 = entry.proc != null ? entry.proc() : null;
var entry = customCommandManager.transactionProcMap[id] ?? throw new GarnetException($"Transaction procedure {id} not found");
return GetCustomTransactionProcedure(entry, txnManager, scratchBufferManager);
}
return sessionTransactionProcMap[id];
}

public (CustomTransactionProcedure, int) GetCustomTransactionProcedure(CustomTransaction entry, TransactionManager txnManager, ScratchBufferManager scratchBufferManager)
{
int id = entry.id;
if (sessionTransactionProcMap[id].Item1 == null)
{
sessionTransactionProcMap[id].Item1 = entry.proc();
sessionTransactionProcMap[id].Item2 = entry.NumParams;

sessionTransactionProcMap[id].Item1.txnManager = txnManager;
Expand Down
5 changes: 4 additions & 1 deletion libs/server/Custom/CustomTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using System;
using Garnet.common;

namespace Garnet.server
{
Expand All @@ -15,11 +16,13 @@ class CustomTransaction

internal CustomTransaction(string name, byte id, int numParams, Func<CustomTransactionProcedure> proc)
{
if (name == null)
throw new GarnetException("CustomTransaction name is null");
nameStr = name.ToUpperInvariant();
this.name = System.Text.Encoding.ASCII.GetBytes(nameStr);
this.id = id;
NumParams = numParams;
this.proc = proc;
this.proc = proc ?? throw new GarnetException("CustomTransactionProcedure is null");
}
}
}
8 changes: 6 additions & 2 deletions playground/Embedded.perftest/EmbeddedPerformanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ public EmbeddedPerformanceTest(EmbeddedRespServer server, Options opts, ILoggerF
this.server = server;
this.opts = opts;
logger = loggerFactory.CreateLogger("EmbeddedBench");
opPercent = opts.OpPercent?.ToArray();
opWorkload = opts.OpWorkload?.ToArray();

if (opts.OpPercent == null || opts.OpWorkload == null)
throw new Exception("OpPercent and OpWorkload must be specified!");

opPercent = opts.OpPercent.ToArray();
opWorkload = opts.OpWorkload.ToArray();

if (opPercent.Length != opWorkload.Length)
throw new Exception($"opPercent {opWorkload.Length} and opWorkload {opWorkload.Length} mismatch!");
Expand Down

0 comments on commit eab149e

Please sign in to comment.