Skip to content

Commit

Permalink
Merge branch 'v5.4' of github.com:ravendb/ravendb into v6.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Voron/Data/Tables/Table.cs
#	src/Voron/Impl/Transaction.cs
#	test/SlowTests/Server/Documents/PeriodicBackup/PeriodicBackupSlowTests.cs
  • Loading branch information
arekpalinski committed Jun 25, 2024
2 parents da80ca5 + bf79035 commit f69028a
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 39 deletions.
11 changes: 6 additions & 5 deletions src/Raven.Server/Documents/Patch/AdminJsConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public string ApplyScript(AdminJsScript script)

try
{
DocumentsOperationContext docsCtx = null;
DocumentsOperationContext databaseCtx = null;
using (_server.AdminScripts.GetScriptRunner(new AdminJsScriptKey(script.Script), false, out var run))
using (_server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext ctx))
using (_database?.DocumentsStorage.ContextPool.AllocateOperationContext(out docsCtx))
using (var result = run.Run(ctx, docsCtx, "execute", new object[] {_server, _database}))
using (_server.ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext serverCtx))
using (_server.ServerStore.Engine.ContextPool.AllocateOperationContext(out ClusterOperationContext clusterCtx))
using (_database?.DocumentsStorage.ContextPool.AllocateOperationContext(out databaseCtx))
using (var result = run.Run(serverCtx, databaseCtx, "execute", new object[] { _server, _database, serverCtx, clusterCtx, databaseCtx }))
{
var toJson = RavenCli.ConvertResultToString(result);

Expand Down Expand Up @@ -102,7 +103,7 @@ public AdminJsScriptKey(string script)

public override void GenerateScript(ScriptRunner runner)
{
runner.AddScript($@"function execute(server, database){{
runner.AddScript($@"function execute(server, database, serverCtx, clusterCtx, databaseCtx){{
{_script}
Expand Down
2 changes: 2 additions & 0 deletions src/Raven.Server/Documents/Patch/BlittableObjectInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public sealed class BlittableObjectInstance : ObjectInstance

public ProjectionOptions Projection;

public BlittableObjectInstance Metadata;

public SpatialResult? Distance => _doc?.Distance;
public float? IndexScore => _doc?.IndexScore;
internal DocumentFlags? DocumentFlags => _doc?.Flags;
Expand Down
10 changes: 8 additions & 2 deletions src/Raven.Server/Documents/Patch/JavaScriptUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Raven.Server.Documents.Indexes.Static.JavaScript;
using Raven.Server.Documents.Queries.Results;
using Raven.Server.Documents.Queries.Results.TimeSeries;
using Raven.Server.ServerWide.Context;
using Sparrow.Json;
using Sparrow.Json.Parsing;

Expand Down Expand Up @@ -142,6 +143,9 @@ internal JsValue GetMetadata(JsValue self, JsValue[] args)
!(args[0].AsObject() is BlittableObjectInstance boi))
throw new InvalidOperationException("metadataFor(doc) must be called with a single entity argument");

if (boi.Metadata != null)
return boi.Metadata;

var modifiedMetadata = new DynamicJsonValue();

// we need to set the metadata on the blittable itself, because we are might get the actual blittable here instead of Document
Expand Down Expand Up @@ -170,8 +174,9 @@ internal JsValue GetMetadata(JsValue self, JsValue[] args)
Context.ReadObject(modifiedMetadata, boi.DocumentId) :
Context.ReadObject(metadata, boi.DocumentId);

JsValue metadataJs = TranslateToJs(_scriptEngine, Context, metadata);
var metadataJs = (BlittableObjectInstance)TranslateToJs(_scriptEngine, Context, metadata);
boi.Set(Constants.Documents.Metadata.Key, metadataJs);
boi.Metadata = metadataJs;

return metadataJs;
}
Expand Down Expand Up @@ -436,9 +441,10 @@ internal JsValue TranslateToJs(Engine engine, JsonOperationContext context, obje
return jsArray;
}
// for admin
if (o is RavenServer || o is DocumentDatabase)
if (o is RavenServer || o is DocumentDatabase || o is DocumentsOperationContext || o is TransactionOperationContext || o is ClusterOperationContext)
{
AssertAdminScriptInstance();

return JsValue.FromObject(engine, o);
}
if (o is ObjectInstance j)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PercentileAggregation(string name = null, double? percentile = null) : ba
if (percentile.Value <= 0 || percentile.Value > 100)
throw new ArgumentOutOfRangeException(
$"Invalid argument passed to '{nameof(AggregationType.Percentile)}' aggregation method: '{percentile}'. " +
"Argument must be a number between 0 and 100");
"Argument must be a number greater than 0 and less than or equal to 100");

_percentileFactor = percentile.Value / 100;
_rankedValues = new List<SortedDictionary<double, int>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public bool Update(UpdateStep step)
{
if (it.Seek(Slices.BeforeAllKeys) == false)
return true;

var stats = new TableSchemaStatsReference();

do
{
var rootObjectType = tx.GetRootObjectType(it.CurrentKey);
Expand All @@ -33,7 +36,7 @@ public bool Update(UpdateStep step)
var writtenSchemaData = tableTree.DirectRead(TableSchema.SchemasSlice);
var writtenSchemaDataSize = tableTree.GetDataSize(TableSchema.SchemasSlice);
var schema = TableSchema.ReadFrom(tx.Allocator, writtenSchemaData, writtenSchemaDataSize);
new Table(schema, it.CurrentKey, tx, tableTree,schema.TableType).AssertValidFixedSizeTrees();
new Table(schema, it.CurrentKey, tx, tableTree, stats, schema.TableType).AssertValidFixedSizeTrees();
}
} while (it.MoveNext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import abstractNotification = require("common/notifications/models/abstractNotif
import notificationCenter = require("common/notifications/notificationCenter");
import recentError = require("common/notifications/models/recentError");
import dialogViewModelBase = require("viewmodels/dialogViewModelBase");
import copyToClipboard from "common/copyToClipboard";

class recentErrorDetails extends dialogViewModelBase {

Expand All @@ -13,7 +14,7 @@ class recentErrorDetails extends dialogViewModelBase {

constructor(recentError: recentError, notificationCenter: notificationCenter) {
super();
this.bindToCurrentInstance("close", "dismiss");
this.bindToCurrentInstance("close", "dismiss", "copyErrorDetails");

this.recentError = recentError;
this.dismissFunction = () => notificationCenter.dismiss(recentError);
Expand All @@ -24,6 +25,11 @@ class recentErrorDetails extends dialogViewModelBase {
this.close();
}

copyErrorDetails(): void {
const errorDetails = this.recentError.details();
copyToClipboard.copy(errorDetails, "Error has been copied to clipboard");
}

static supportsDetailsFor(notification: abstractNotification) {
return notification instanceof recentError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ <h3 class="modal-title" id="myModalLabel" data-bind="text: title, attr: { class:
</div>
<div class="modal-body" data-bind="with: recentError">
<div data-bind="html: longerMessage"></div>
<pre class="margin-top error-messages" data-bind="visible: details"><code data-bind="text: details"></code></pre>
<div class="d-flex margin-top" data-bind="visible: details">
<div class="flex-grow"></div>
<button class="btn btn-default btn-sm" data-bind="click: $parent.copyErrorDetails"><i class="icon-copy-to-clipboard"></i><span>Copy error message</span></button>
</div>
<pre class="d-flex error-messages position-relative" data-bind="visible: details">
<code data-bind="text: details"></code>
</pre>
</div>
<div class="modal-footer">
<div class="flex-horizontal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
<span class="help-block" data-bind="validationMessage: factoryName"></span>
<div class="has-warning" data-bind="visible: factoryName() === 'MySql.Data.MySqlClient'">
<div class="help-block">
<i class="icon-warning"></i> <span> This connector is deprecated</span>
<i class="icon-warning"></i>
<span>
This connector is deprecated.
MySqlConnector will be used instead.
Please update Factory to: MySqlConnector.MySqlConnectorFactory.
</span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ <h4>Create new import configuration</h4>
<span class="help-block" data-bind="validationMessage: databaseType"></span>
<div class="has-warning" data-bind="visible: databaseType() === 'MySQL_MySql_Data'">
<div class="help-block">
<i class="icon-warning"></i> <span> This connector is deprecated</span>
<i class="icon-warning"></i>
<span>
This connector is deprecated.
MySqlConnector will be used instead.
Please update Factory to: MySqlConnector.MySqlConnectorFactory.
</span>
</div>
</div>
</div>
Expand Down
42 changes: 17 additions & 25 deletions src/Voron/Data/Tables/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public sealed unsafe class Table
private readonly byte _tableType;
private int? _currentCompressionDictionaryId;

public long NumberOfEntries { get; private set; }
public long NumberOfEntries => _stats.NumberOfEntries;

private long _overflowPageCount;
private readonly TableSchemaStatsReference _stats;
private NewPageAllocator _tablePageAllocator;
private NewPageAllocator _globalPageAllocator;

Expand Down Expand Up @@ -132,24 +132,19 @@ private void OnDataMoved(long previousId, long newId, byte* data, int size, bool
/// Using this constructor WILL NOT register the Table for commit in
/// the Transaction, and hence changes WILL NOT be committed.
/// </summary>
public Table(TableSchema schema, Slice name, Transaction tx, Tree tableTree, byte tableType, bool doSchemaValidation = false)
public Table(TableSchema schema, Slice name, Transaction tx, Tree tableTree, TableSchemaStatsReference stats, byte tableType, bool doSchemaValidation = false)
{
Name = name;

_schema = schema;
_tx = tx;
_tableType = tableType;
_stats = stats;

_tableTree = tableTree;
if (_tableTree == null)
throw new ArgumentNullException(nameof(tableTree), "Cannot open table " + Name);

var stats = (TableSchemaStats*)_tableTree.DirectRead(TableSchema.StatsSlice);
if (stats == null)
throw new InvalidDataException($"Cannot find stats value for table {name}");

NumberOfEntries = stats->NumberOfEntries;
_overflowPageCount = stats->OverflowPageCount;

if (doSchemaValidation)
{
Expand Down Expand Up @@ -523,22 +518,22 @@ public void Delete(long id)
{
var page = _tx.LowLevelTransaction.GetPage(id / Constants.Storage.PageSize);
var numberOfPages = VirtualPagerLegacyExtensions.GetNumberOfOverflowPages(page.OverflowSize);
_overflowPageCount -= numberOfPages;
_stats.OverflowPageCount -= numberOfPages;

for (var i = 0; i < numberOfPages; i++)
{
_tx.LowLevelTransaction.FreePage(page.PageNumber + i);
}
}

NumberOfEntries--;
_stats.NumberOfEntries--;

using (_tableTree.DirectAdd(TableSchema.StatsSlice, sizeof(TableSchemaStats), out byte* updatePtr))
{
var stats = (TableSchemaStats*)updatePtr;

stats->NumberOfEntries = NumberOfEntries;
stats->OverflowPageCount = _overflowPageCount;
stats->NumberOfEntries = _stats.NumberOfEntries;
stats->OverflowPageCount = _stats.OverflowPageCount;
}

if (largeValue)
Expand Down Expand Up @@ -725,14 +720,14 @@ public long Insert(TableValueBuilder builder)
var tvr = builder.CreateReader(pos);
InsertIndexValuesFor(id, ref tvr);

NumberOfEntries++;
_stats.NumberOfEntries++;

using (_tableTree.DirectAdd(TableSchema.StatsSlice, sizeof(TableSchemaStats), out byte* ptr))
{
var stats = (TableSchemaStats*)ptr;

stats->NumberOfEntries = NumberOfEntries;
stats->OverflowPageCount = _overflowPageCount;
stats->NumberOfEntries = _stats.NumberOfEntries;
stats->OverflowPageCount = _stats.OverflowPageCount;
}

return id;
Expand All @@ -742,7 +737,7 @@ private Page AllocatePageForLargeValue(int size, bool compressed)
{
var numberOfOverflowPages = VirtualPagerLegacyExtensions.GetNumberOfOverflowPages(size);
var page = _tx.LowLevelTransaction.AllocatePage(numberOfOverflowPages);
_overflowPageCount += numberOfOverflowPages;
_stats.OverflowPageCount += numberOfOverflowPages;

page.Flags = PageFlags.Overflow | PageFlags.RawData;
if (compressed)
Expand Down Expand Up @@ -1007,8 +1002,6 @@ internal long Insert(ref TableValueReader reader)

using var __ = Allocate(out var builder);

ByteStringContext<ByteStringMemoryCache>.ExternalScope rawCompressBufferScore = default;

byte* dataPtr = reader.Pointer;
int dataSize = reader.Size;
bool compressed = false;
Expand All @@ -1035,7 +1028,7 @@ internal long Insert(ref TableValueReader reader)
{
var numberOfOverflowPages = VirtualPagerLegacyExtensions.GetNumberOfOverflowPages(dataSize);
var page = _tx.LowLevelTransaction.AllocatePage(numberOfOverflowPages);
_overflowPageCount += numberOfOverflowPages;
_stats.OverflowPageCount += numberOfOverflowPages;

page.Flags = PageFlags.Overflow | PageFlags.RawData;
page.OverflowSize = dataSize;
Expand All @@ -1055,17 +1048,16 @@ internal long Insert(ref TableValueReader reader)

InsertIndexValuesFor(id, ref reader);

NumberOfEntries++;
_stats.NumberOfEntries++;

using (_tableTree.DirectAdd(TableSchema.StatsSlice, sizeof(TableSchemaStats), out byte* ptr))
{
var stats = (TableSchemaStats*)ptr;

stats->NumberOfEntries = NumberOfEntries;
stats->OverflowPageCount = _overflowPageCount;
stats->NumberOfEntries = _stats.NumberOfEntries;
stats->OverflowPageCount = _stats.OverflowPageCount;
}

rawCompressBufferScore.Dispose();
return id;
}

Expand Down Expand Up @@ -2370,7 +2362,7 @@ public TableReport GetReport(bool includeDetails, StorageReportGenerator generat
{
generatorInstance ??= new StorageReportGenerator(_tx.LowLevelTransaction);

var overflowSize = _overflowPageCount * Constants.Storage.PageSize;
var overflowSize = _stats.OverflowPageCount * Constants.Storage.PageSize;
var report = new TableReport(overflowSize, overflowSize, includeDetails, generatorInstance)
{
Name = Name.ToString(),
Expand Down
8 changes: 8 additions & 0 deletions src/Voron/Data/Tables/TableSchemaStatsReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Voron.Data.Tables;

public class TableSchemaStatsReference
{
public long NumberOfEntries { get; set; }

public long OverflowPageCount { get; set; }
}
19 changes: 18 additions & 1 deletion src/Voron/Impl/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Voron.Data.PostingLists;
using Constants = Voron.Global.Constants;
using System.Diagnostics.CodeAnalysis;
using System.IO;

namespace Voron.Impl
{
Expand All @@ -37,6 +38,7 @@ public LowLevelTransaction LowLevelTransaction
private Dictionary<Slice, PostingList> _postingLists;

private Dictionary<TableKey, Table> _tables;
private Dictionary<Slice, TableSchemaStatsReference> _tableSchemaStats;

private Dictionary<Slice, Tree> _trees;

Expand Down Expand Up @@ -252,7 +254,22 @@ public Table OpenTable(TableSchema schema, Slice name)
if (tableTree == null)
return null;

value = new Table(schema, clonedName, this, tableTree, schema.TableType);
_tableSchemaStats ??= new Dictionary<Slice, TableSchemaStatsReference>(SliceComparer.Instance);

if (_tableSchemaStats.TryGetValue(clonedName, out var tableStatsRef) == false)
{
var stats = (TableSchemaStats*)tableTree.DirectRead(TableSchema.StatsSlice);
if (stats == null)
throw new InvalidDataException($"Cannot find stats value for table {name}");

_tableSchemaStats[clonedName] = tableStatsRef = new TableSchemaStatsReference()
{
NumberOfEntries = stats->NumberOfEntries,
OverflowPageCount = stats->OverflowPageCount
};
}

value = new Table(schema, clonedName, this, tableTree, tableStatsRef, schema.TableType);
_tables[key] = value;
return value;
}
Expand Down
Loading

0 comments on commit f69028a

Please sign in to comment.