Skip to content

Commit

Permalink
Merge pull request #49 from vb2ae/Fix-virtual-calls-in-constructor
Browse files Browse the repository at this point in the history
fix Virtual call in constructor or destructor
  • Loading branch information
vb2ae authored Oct 23, 2023
2 parents 7d078ed + d196de6 commit dc41b44
Show file tree
Hide file tree
Showing 3 changed files with 320 additions and 296 deletions.
13 changes: 12 additions & 1 deletion ClientNoSqlDB/Storage/FileSystem/DbTableStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public DbTableStorage(string path, string name)

readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();

public void Initialize()
{

}
public void Flush()
{
}
Expand Down Expand Up @@ -61,7 +65,9 @@ public IDbTableReader BeginRead()
_lock.EnterReadLock();
try
{
return new Reader(this, _lock.ExitReadLock);
Reader reader = new Reader(this, _lock.ExitReadLock);
reader.Initialize();
return reader;
}
catch
{
Expand Down Expand Up @@ -109,6 +115,10 @@ public Reader(DbTableStorage table, Action finalizer)
{
_table = table;
_finalizer = finalizer;
}

public void Initialize()
{
CreateStreams();
UpdateTs();
}
Expand Down Expand Up @@ -187,6 +197,7 @@ class Writer : Reader, IDbTableWriter
public Writer(DbTableStorage table, Action finalizer)
: base(table, finalizer)
{
base.Initialize();
}

protected override void CreateStreams()
Expand Down
99 changes: 50 additions & 49 deletions ClientNoSqlDB/Storage/Interfaces/IDbTableStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,63 @@

namespace ClientNoSqlDB
{
/// <summary>
/// Table size information container
/// </summary>
public class DbTableInfo
{
/// <summary>
/// Actual size of the index file
/// Table size information container
/// </summary>
public long IndexSize;
public class DbTableInfo
{
/// <summary>
/// Actual size of the index file
/// </summary>
public long IndexSize;

/// <summary>
/// Actual size of the data file (including gaps)
/// </summary>
public long DataSize;
/// <summary>
/// Actual size of the data file (including gaps)
/// </summary>
public long DataSize;

/// <summary>
/// Effective size of the data file (excluding gaps)
/// </summary>
public long EffectiveDataSize;
/// <summary>
/// Effective size of the data file (excluding gaps)
/// </summary>
public long EffectiveDataSize;

/// <summary>
/// Summs all numeric properties
/// </summary>
public static DbTableInfo operator +(DbTableInfo a, DbTableInfo b)
{
return new DbTableInfo
{
DataSize = a.DataSize + b.DataSize,
IndexSize = a.IndexSize + b.IndexSize,
EffectiveDataSize = a.EffectiveDataSize + b.EffectiveDataSize
};
/// <summary>
/// Summs all numeric properties
/// </summary>
public static DbTableInfo operator +(DbTableInfo a, DbTableInfo b)
{
return new DbTableInfo
{
DataSize = a.DataSize + b.DataSize,
IndexSize = a.IndexSize + b.IndexSize,
EffectiveDataSize = a.EffectiveDataSize + b.EffectiveDataSize
};
}
}
}

interface IDbTableStorage
{
IDbTableReader BeginRead();
IDbTableWriter BeginWrite();
IDbTableWriter BeginCompact();
void Flush();
}
interface IDbTableStorage
{
void Initialize();
IDbTableReader BeginRead();
IDbTableWriter BeginWrite();
IDbTableWriter BeginCompact();
void Flush();
}

interface IDbTableReader : IDisposable
{
DateTimeOffset Ts { get; }
byte[] ReadIndex();
byte[] ReadData(long position, int length);
DbTableInfo GetInfo();
}
interface IDbTableReader : IDisposable
{
DateTimeOffset Ts { get; }
byte[] ReadIndex();
byte[] ReadData(long position, int length);
DbTableInfo GetInfo();
}

interface IDbTableWriter : IDbTableReader
{
DateTimeOffset WriteIndex(byte[] data, int length);
void WriteData(byte[] data, long position, int length);
void CopyData(long position, long target, int length);
void CropData(long position);
void Purge();
}
interface IDbTableWriter : IDbTableReader
{
DateTimeOffset WriteIndex(byte[] data, int length);
void WriteData(byte[] data, long position, int length);
void CopyData(long position, long target, int length);
void CropData(long position);
void Purge();
}
}
Loading

0 comments on commit dc41b44

Please # to comment.