Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove facetconfig locks #410

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 26 additions & 50 deletions src/Lucene.Net.Facet/FacetsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ public class FacetsConfig
/// </summary>
public const string DEFAULT_INDEX_FIELD_NAME = "$facets";

private readonly IDictionary<string, DimConfig> fieldTypes = new ConcurrentDictionary<string, DimConfig>();
private readonly ConcurrentDictionary<string, DimConfig> fieldTypes = new ConcurrentDictionary<string, DimConfig>();

// Used only for best-effort detection of app mixing
// int/float/bytes in a single indexed field:
private readonly IDictionary<string, string> assocDimTypes = new ConcurrentDictionary<string, string>();

private readonly object syncLock = new object(); // LUCENENET specific - avoid lock(this)
private readonly ConcurrentDictionary<string, string> assocDimTypes = new ConcurrentDictionary<string, string>();

/// <summary>
/// Holds the configuration for one dimension
Expand Down Expand Up @@ -140,14 +138,12 @@ public FacetsConfig()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual DimConfig GetDimConfig(string dimName)
{
lock (syncLock)
if (!fieldTypes.TryGetValue(dimName, out DimConfig ft))
{
if (!fieldTypes.TryGetValue(dimName, out DimConfig ft))
{
ft = DefaultDimConfig;
}
return ft;
ft = DefaultDimConfig;
}

return ft;
}

/// <summary>
Expand All @@ -157,18 +153,13 @@ public virtual DimConfig GetDimConfig(string dimName)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void SetHierarchical(string dimName, bool v)
{
lock (syncLock)
{
// LUCENENET: Eliminated extra lookup by using TryGetValue instead of ContainsKey
if (!fieldTypes.TryGetValue(dimName, out DimConfig fieldType))
{
fieldTypes[dimName] = new DimConfig { IsHierarchical = v };
}
else
// LUCENENET: Eliminated extra lookup by using AddOrUpdate instead of ContainsKey
fieldTypes.AddOrUpdate(dimName, _ => new DimConfig {IsHierarchical = v},
(_, fieldType) =>
{
fieldType.IsHierarchical = v;
}
}
return fieldType;
});
}

/// <summary>
Expand All @@ -178,18 +169,13 @@ public virtual void SetHierarchical(string dimName, bool v)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void SetMultiValued(string dimName, bool v)
{
lock (syncLock)
{
// LUCENENET: Eliminated extra lookup by using TryGetValue instead of ContainsKey
if (!fieldTypes.TryGetValue(dimName, out DimConfig fieldType))
{
fieldTypes[dimName] = new DimConfig { IsMultiValued = v };
}
else
// LUCENENET: Eliminated extra lookup by using AddOrUpdate instead of ContainsKey
fieldTypes.AddOrUpdate(dimName, _ => new DimConfig {IsMultiValued = v},
(_, fieldType) =>
{
fieldType.IsMultiValued = v;
}
}
return fieldType;
});
}

/// <summary>
Expand All @@ -200,18 +186,13 @@ public virtual void SetMultiValued(string dimName, bool v)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void SetRequireDimCount(string dimName, bool v)
{
lock (syncLock)
{
// LUCENENET: Eliminated extra lookup by using TryGetValue instead of ContainsKey
if (!fieldTypes.TryGetValue(dimName, out DimConfig fieldType))
{
fieldTypes[dimName] = new DimConfig { RequireDimCount = v };
}
else
// LUCENENET: Eliminated extra lookup by using AddOrUpdate instead of ContainsKey
fieldTypes.AddOrUpdate(dimName, _ => new DimConfig {RequireDimCount = v},
(_, fieldType) =>
{
fieldType.RequireDimCount = v;
}
}
return fieldType;
});
}

/// <summary>
Expand All @@ -221,18 +202,13 @@ public virtual void SetRequireDimCount(string dimName, bool v)
/// </summary>
public virtual void SetIndexFieldName(string dimName, string indexFieldName)
{
lock (syncLock)
{
// LUCENENET: Eliminated extra lookup by using TryGetValue instead of ContainsKey
if (!fieldTypes.TryGetValue(dimName, out DimConfig fieldType))
{
fieldTypes[dimName] = new DimConfig { IndexFieldName = indexFieldName };
}
else
// LUCENENET: Eliminated extra lookup by using AddOrUpdate instead of ContainsKey
fieldTypes.AddOrUpdate(dimName, _ => new DimConfig {IndexFieldName = indexFieldName},
(_, fieldType) =>
{
fieldType.IndexFieldName = indexFieldName;
}
}
return fieldType;
});
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Facet/Taxonomy/DocValuesOrdinalsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected virtual void Decode(BytesRef buf, Int32sRef ordinals)
while (offset < upto)
{
byte b = buf.Bytes[offset++];
if ((sbyte)b >= 0)
if (b <= 127)
{
ordinals.Int32s[ordinals.Length] = ((value << 7) | b) + prev;
value = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Facet/Taxonomy/FastTaxonomyFacetCounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void Count(IList<FacetsCollector.MatchingDocs> matchingDocs)
while (offset < end)
{
byte b = bytes[offset++];
if ((sbyte)b >= 0)
if (b <= 127)
{
prev = ord = ((ord << 7) | b) + prev;
++m_values[ord];
Expand Down
26 changes: 13 additions & 13 deletions src/Lucene.Net/Store/BufferedIndexInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,26 @@ public override sealed int ReadVInt32()
if (5 <= (bufferLength - bufferPosition))
{
byte b = m_buffer[bufferPosition++];
if ((sbyte)b >= 0)
if (b <= 127)
{
return b;
}
int i = b & 0x7F;
b = m_buffer[bufferPosition++];
i |= (b & 0x7F) << 7;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7F) << 14;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7F) << 21;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
Expand All @@ -306,56 +306,56 @@ public override sealed long ReadVInt64()
if (9 <= bufferLength - bufferPosition)
{
byte b = m_buffer[bufferPosition++];
if ((sbyte)b >= 0)
if (b <= 127)
{
return b;
}
long i = b & 0x7FL;
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 7;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 14;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 21;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 28;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 35;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 42;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 49;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = m_buffer[bufferPosition++];
i |= (b & 0x7FL) << 56;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
Expand Down
30 changes: 15 additions & 15 deletions src/Lucene.Net/Store/ByteArrayDataInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace Lucene.Net.Store
{
Expand Down Expand Up @@ -93,7 +93,7 @@ public override void SkipBytes(long count)
/// </summary>
public override short ReadInt16()
{
return (short)(ushort)(((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF));
return (short)Math.Abs(((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF));
}

/// <summary>
Expand Down Expand Up @@ -123,26 +123,26 @@ public override long ReadInt64()
public override int ReadVInt32()
{
byte b = bytes[pos++];
if ((sbyte)b >= 0)
if (b <= 127)
{
return b;
}
int i = b & 0x7F;
b = bytes[pos++];
i |= (b & 0x7F) << 7;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7F) << 14;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7F) << 21;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
Expand All @@ -162,56 +162,56 @@ public override int ReadVInt32()
public override long ReadVInt64()
{
byte b = bytes[pos++];
if ((sbyte)b >= 0)
if (b <= 127)
{
return b;
}
long i = b & 0x7FL;
b = bytes[pos++];
i |= (b & 0x7FL) << 7;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 14;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 21;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 28;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 35;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 42;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 49;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
b = bytes[pos++];
i |= (b & 0x7FL) << 56;
if ((sbyte)b >= 0)
if (b <= 127)
{
return i;
}
Expand Down
Loading