forked from OrleansContrib/Orleans.Indexing-1.5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActiveIndexAttribute.cs
More file actions
74 lines (71 loc) · 3.23 KB
/
ActiveIndexAttribute.cs
File metadata and controls
74 lines (71 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
namespace Orleans.Indexing
{
/// <summary>
/// The attribute for declaring the property fields of an
/// indexed grain interface to have an "Active Index".
///
/// An "Active Index" indexes all the grains that are
/// currently active in the silos.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class ActiveIndexAttribute : IndexAttribute
{
/// <summary>
/// The default constructor for ActiveIndex.
/// </summary>
public ActiveIndexAttribute() : this(false)
{
}
/// <summary>
/// The constructor for ActiveIndex.
/// </summary>
/// <param name="IsEager">Determines whether the index should be
/// updated eagerly upon any change in the indexed grains. Otherwise,
/// the update propagation happens lazily after applying the update
/// to the grain itself.</param>
public ActiveIndexAttribute(bool IsEager) : this(Indexing.ActiveIndexType.HashIndexSingleBucket, IsEager)
{
}
/// <summary>
/// The full-option constructor for ActiveIndex.
/// </summary>
/// <param name="type">The index type for the active index</param>
/// <param name="IsEager">Determines whether the index should be
/// updated eagerly upon any change in the indexed grains. Otherwise,
/// the update propagation happens lazily after applying the update
/// to the grain itself.</param>
/// <param name="MaxEntriesPerBucket">The maximum number of entries
/// that should be stored in each bucket of a distributed index. This
/// option is only considered if the index is a distributed index.
/// Use -1 to declare no limit.</param>
public ActiveIndexAttribute(ActiveIndexType type, bool IsEager = false, int MaxEntriesPerBucket = -1)
{
switch (type)
{
case Indexing.ActiveIndexType.HashIndexSingleBucket:
IndexType = typeof(ActiveHashIndexSingleBucket<,>);
break;
case Indexing.ActiveIndexType.HashIndexPartitionedByKeyHash:
IndexType = typeof(ActiveHashIndexPartitionedPerKey<,>);
break;
case Indexing.ActiveIndexType.HashIndexPartitionedBySilo:
IndexType = typeof(ActiveHashIndexPartitionedPerSilo<,>);
break;
default:
IndexType = typeof(ActiveHashIndexSingleBucket<,>);
break;
}
this.IsEager = IsEager;
//Active Index cannot be defined as unique
//Suppose there's a unique Active Index over persistent objects.
//The activation of an initialized object could create a conflict in
//the Active Index. E.g., there's an active player PA with email foo and
//a non-active persistent player PP with email foo. An attempt to
//activate PP will cause a violation of the Active Index on email.
//This implies we should disallow such indexes.
this.IsUnique = false;
this.MaxEntriesPerBucket = MaxEntriesPerBucket;
}
}
}