-
Notifications
You must be signed in to change notification settings - Fork 17
/
map_types.go
489 lines (397 loc) · 16.9 KB
/
map_types.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
package v1alpha1
import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// MapSpec defines the desired state of Hazelcast Map Config
type MapSpec struct {
DataStructureSpec `json:",inline"`
// Maximum time in seconds for each entry to stay in the map.
// If it is not 0, entries that are older than this time and not updated for this time are evicted automatically.
// It can be updated.
// +kubebuilder:default:=0
// +optional
TimeToLiveSeconds int32 `json:"timeToLiveSeconds"`
// Maximum time in seconds for each entry to stay idle in the map.
// Entries that are idle for more than this time are evicted automatically.
// It can be updated.
// +kubebuilder:default:=0
// +optional
MaxIdleSeconds int32 `json:"maxIdleSeconds"`
// Configuration for removing data from the map when it reaches its max size.
// It can be updated.
// +kubebuilder:default:={maxSize: 0, evictionPolicy: NONE, maxSizePolicy: PER_NODE}
// +optional
Eviction EvictionConfig `json:"eviction,omitempty"`
// Indexes to be created for the map data.
// You can learn more at https://docs.hazelcast.com/hazelcast/latest/query/indexing-maps.
// It cannot be updated after map config is created successfully.
// +optional
Indexes []IndexConfig `json:"indexes,omitempty"`
// Attributes to be used with Predicates API.
// You can learn more at https://docs.hazelcast.com/hazelcast/latest/query/predicate-overview#creating-custom-query-attributes
// +optional
Attributes []AttributeConfig `json:"attributes,omitempty"`
// When enabled, map data will be persisted.
// It cannot be updated after map config is created successfully.
// +kubebuilder:default:=false
// +optional
PersistenceEnabled bool `json:"persistenceEnabled"`
// Configuration options when you want to load/store the map entries
// from/to a persistent data store such as a relational database
// You can learn more at https://docs.hazelcast.com/hazelcast/latest/data-structures/working-with-external-data
// +optional
MapStore *MapStoreConfig `json:"mapStore,omitempty"`
// InMemoryFormat specifies in which format data will be stored in your map
// +kubebuilder:default:=BINARY
// +optional
InMemoryFormat InMemoryFormatType `json:"inMemoryFormat,omitempty"`
// EntryListeners contains the configuration for the map-level or entry-based events listeners
// provided by the Hazelcast’s eventing framework.
// You can learn more at https://docs.hazelcast.com/hazelcast/latest/events/object-events.
// +optional
EntryListeners []EntryListenerConfiguration `json:"entryListeners,omitempty"`
// InMemoryFormat specifies near cache configuration for map
// +optional
NearCache *NearCache `json:"nearCache"`
// EventJournal specifies event journal configuration of the Map
// +optional
EventJournal *EventJournal `json:"eventJournal,omitempty"`
// TieredStore enables the Hazelcast's Tiered-Store feature for the Map
// +optional
TieredStore *TieredStore `json:"tieredStore,omitempty"`
// MerkleTree defines the configuration for the Merkle tree data structure.
// +optional
MerkleTree *MerkleTreeConfig `json:"merkleTree,omitempty"`
}
type MerkleTreeConfig struct {
// Depth of the merkle tree.
// +kubebuilder:default:=10
Depth int32 `json:"depth,omitempty"`
}
type NearCache struct {
// Name is name of the near cache
// +kubebuilder:default:=default
// +optional
Name string `json:"name,omitempty"`
// InMemoryFormat specifies in which format data will be stored in your near cache
// +kubebuilder:default:=BINARY
// +optional
InMemoryFormat InMemoryFormatType `json:"inMemoryFormat,omitempty"`
// InvalidateOnChange specifies whether the cached entries are evicted when the entries are updated or removed
// +kubebuilder:default:=true
// +optional
InvalidateOnChange *bool `json:"invalidateOnChange,omitempty"`
// TimeToLiveSeconds maximum number of seconds for each entry to stay in the Near Cache
// +kubebuilder:default:=0
// +optional
TimeToLiveSeconds uint `json:"timeToLiveSeconds,omitempty"`
// MaxIdleSeconds Maximum number of seconds each entry can stay in the Near Cache as untouched (not read)
// +kubebuilder:default:=0
// +optional
MaxIdleSeconds uint `json:"maxIdleSeconds,omitempty"`
// NearCacheEviction specifies the eviction behavior in Near Cache
// +kubebuilder:default:={evictionPolicy: NONE, maxSizePolicy: ENTRY_COUNT}
NearCacheEviction NearCacheEviction `json:"eviction"`
// CacheLocalEntries specifies whether the local entries are cached
// +kubebuilder:default:=true
// +optional
CacheLocalEntries *bool `json:"cacheLocalEntries,omitempty"`
}
type NearCacheEviction struct {
// EvictionPolicy to be applied when near cache reaches its max size according to the max size policy.
// +kubebuilder:default:="NONE"
// +optional
EvictionPolicy EvictionPolicyType `json:"evictionPolicy,omitempty"`
// MaxSizePolicy for deciding if the maxSize is reached.
// +kubebuilder:default:="ENTRY_COUNT"
// +optional
MaxSizePolicy MaxSizePolicyType `json:"maxSizePolicy,omitempty"`
// Size is maximum size of the Near Cache used for max-size-policy
// +kubebuilder:default:=0
// +optional
Size uint32 `json:"size"`
}
type EntryListenerConfiguration struct {
// ClassName is the fully qualified name of the class that implements any of the Listener interface.
// +kubebuilder:validation:MinLength:=1
// +required
ClassName string `json:"className"`
// IncludeValues is an optional attribute that indicates whether the event will contain the map value.
// Defaults to true.
// +kubebuilder:default:=true
// +optional
IncludeValues *bool `json:"includeValues,omitempty"`
// Local is an optional attribute that indicates whether the map on the local member can be listened to.
// Defaults to false.
// +kubebuilder:default:=false
// +optional
Local bool `json:"local"`
}
func (e *EntryListenerConfiguration) GetIncludedValue() bool {
if e.IncludeValues == nil {
return true
}
return *e.IncludeValues
}
type EvictionConfig struct {
// Eviction policy to be applied when map reaches its max size according to the max size policy.
// +kubebuilder:default:="NONE"
// +optional
EvictionPolicy EvictionPolicyType `json:"evictionPolicy,omitempty"`
// Max size of the map.
// +kubebuilder:default:=0
// +optional
MaxSize int32 `json:"maxSize"`
// Policy for deciding if the maxSize is reached.
// +kubebuilder:default:="PER_NODE"
// +optional
MaxSizePolicy MaxSizePolicyType `json:"maxSizePolicy,omitempty"`
}
// +kubebuilder:validation:Enum=PER_NODE;PER_PARTITION;USED_HEAP_SIZE;USED_HEAP_PERCENTAGE;FREE_HEAP_SIZE;FREE_HEAP_PERCENTAGE;USED_NATIVE_MEMORY_SIZE;USED_NATIVE_MEMORY_PERCENTAGE;FREE_NATIVE_MEMORY_SIZE;FREE_NATIVE_MEMORY_PERCENTAGE;ENTRY_COUNT
type MaxSizePolicyType string
const (
// Maximum number of map entries in each cluster member.
// You cannot set the max-size to a value lower than the partition count (which is 271 by default).
MaxSizePolicyPerNode MaxSizePolicyType = "PER_NODE"
// Maximum number of map entries within each partition.
MaxSizePolicyPerPartition MaxSizePolicyType = "PER_PARTITION"
// Maximum used heap size percentage per map for each Hazelcast instance.
// If, for example, JVM is configured to have 1000 MB and this value is 10, then the map entries will be evicted when used heap size
// exceeds 100 MB. It does not work when "in-memory-format" is set to OBJECT.
MaxSizePolicyUsedHeapPercentage MaxSizePolicyType = "USED_HEAP_PERCENTAGE"
// Maximum used heap size in megabytes per map for each Hazelcast instance. It does not work when "in-memory-format" is set to OBJECT.
MaxSizePolicyUsedHeapSize MaxSizePolicyType = "USED_HEAP_SIZE"
// Minimum free heap size percentage for each Hazelcast instance. If, for example, JVM is configured to
// have 1000 MB and this value is 10, then the map entries will be evicted when free heap size is below 100 MB.
MaxSizePolicyFreeHeapPercentage MaxSizePolicyType = "FREE_HEAP_PERCENTAGE"
// Minimum free heap size in megabytes for each Hazelcast instance.
MaxSizePolicyFreeHeapSize MaxSizePolicyType = "FREE_HEAP_SIZE"
// Maximum used native memory size in megabytes per map for each Hazelcast instance. It is available only in
// Hazelcast Enterprise HD.
MaxSizePolicyUsedNativeMemorySize MaxSizePolicyType = "USED_NATIVE_MEMORY_SIZE"
// Maximum used native memory size percentage per map for each Hazelcast instance. It is available only in
// Hazelcast Enterprise HD.
MaxSizePolicyUsedNativeMemoryPercentage MaxSizePolicyType = "USED_NATIVE_MEMORY_PERCENTAGE"
// Minimum free native memory size in megabytes for each Hazelcast instance. It is available only in
// Hazelcast Enterprise HD.
MaxSizePolicyFreeNativeMemorySize MaxSizePolicyType = "FREE_NATIVE_MEMORY_SIZE"
// Minimum free native memory size percentage for each Hazelcast instance. It is available only in
// Hazelcast Enterprise HD.
MaxSizePolicyFreeNativeMemoryPercentage MaxSizePolicyType = "FREE_NATIVE_MEMORY_PERCENTAGE"
// Maximum size based on the entry count in the Near Cache
// Warning: This policy is specific to near cache.
MaxSizePolicyEntryCount MaxSizePolicyType = "ENTRY_COUNT"
)
// +kubebuilder:validation:Enum=NONE;LRU;LFU;RANDOM
type EvictionPolicyType string
const (
// Least recently used entries will be removed.
EvictionPolicyLRU EvictionPolicyType = "LRU"
// Least frequently used entries will be removed.
EvictionPolicyLFU EvictionPolicyType = "LFU"
// No eviction.
EvictionPolicyNone EvictionPolicyType = "NONE"
// Randomly selected entries will be removed.
EvictionPolicyRandom EvictionPolicyType = "RANDOM"
)
type IndexConfig struct {
// Name of the index config.
// +optional
Name string `json:"name,omitempty"`
// Type of the index. See https://docs.hazelcast.com/hazelcast/latest/query/indexing-maps#index-types
// +required
Type IndexType `json:"type"`
// Attributes of the index.
// +optional
Attributes []string `json:"attributes,omitempty"`
// Options for "BITMAP" index type. See https://docs.hazelcast.com/hazelcast/latest/query/indexing-maps#configuring-bitmap-indexes
// +kubebuilder:default:={}
// +optional
BitmapIndexOptions *BitmapIndexOptionsConfig `json:"bitMapIndexOptions,omitempty"`
}
type AttributeConfig struct {
// Name of the attribute https://docs.hazelcast.com/hazelcast/latest/query/predicate-overview#creating-custom-query-attributes
// +required
Name string `json:"name"`
// Name of the extractor class https://docs.hazelcast.com/hazelcast/latest/query/predicate-overview#implementing-a-valueextractor
// +required
ExtractorClassName string `json:"extractorClassName"`
}
// +kubebuilder:validation:Enum=SORTED;HASH;BITMAP
type IndexType string
const (
IndexTypeSorted IndexType = "SORTED"
IndexTypeHash IndexType = "HASH"
IndexTypeBitmap IndexType = "BITMAP"
)
type BitmapIndexOptionsConfig struct {
// +required
UniqueKey string `json:"uniqueKey"`
// +required
UniqueKeyTransition UniqueKeyTransition `json:"uniqueKeyTransition"`
}
// +kubebuilder:validation:Enum=OBJECT;LONG;RAW
type UniqueKeyTransition string
const (
UniqueKeyTransitionObject UniqueKeyTransition = "OBJECT"
UniqueKeyTransitionLong UniqueKeyTransition = "LONG"
UniqueKeyTransitionRAW UniqueKeyTransition = "RAW"
)
// MapStatus defines the observed state of Map
type MapStatus struct {
// +optional
State MapConfigState `json:"state,omitempty"`
// +optional
Message string `json:"message,omitempty"`
// +optional
MemberStatuses map[string]MapConfigState `json:"memberStatuses,omitempty"`
}
// +kubebuilder:validation:Enum=Success;Failed;Pending;Persisting;Terminating
type MapConfigState string
const (
MapFailed MapConfigState = "Failed"
MapSuccess MapConfigState = "Success"
MapPending MapConfigState = "Pending"
// Map config is added into all members but waiting for map to be persistent into ConfigMap
MapPersisting MapConfigState = "Persisting"
MapTerminating MapConfigState = "Terminating"
)
type MapStoreConfig struct {
// Sets the initial entry loading mode.
// +kubebuilder:default:=LAZY
// +optional
InitialMode InitialModeType `json:"initialMode,omitempty"`
// Name of your class implementing MapLoader and/or MapStore interface.
// +required
ClassName string `json:"className"`
// Number of seconds to delay the storing of entries.
// +kubebuilder:default:0
// +optional
WriteDelaySeconds int32 `json:"writeDelaySeconds"`
// Used to create batches when writing to map store.
// +kubebuilder:default:=1
// +kubebuilder:validation:Minimum=1
// +optional
WriteBatchSize int32 `json:"writeBatchSize,omitempty"`
// It is meaningful if you are using write behind in MapStore. When it is set to true,
// only the latest store operation on a key during the write-delay-seconds will be
// reflected to MapStore.
// +kubebuilder:default:=true
// +optional
WriteCoealescing *bool `json:"writeCoalescing,omitempty"`
// Properties can be used for giving information to the MapStore implementation
// +optional
PropertiesSecretName string `json:"propertiesSecretName,omitempty"`
}
// +kubebuilder:validation:Enum=LAZY;EAGER
type InitialModeType string
const (
// Loading is asynchronous. It is the default mode.
InitialModeLazy InitialModeType = "LAZY"
// Loading is blocked until all partitions are loaded.
InitialModeEager InitialModeType = "EAGER"
)
// InMemoryFormatType represents the format options for storing the data in the map/cache.
// +kubebuilder:validation:Enum=BINARY;OBJECT;NATIVE
type InMemoryFormatType string
const (
// InMemoryFormatBinary Data will be stored in serialized binary format.
InMemoryFormatBinary InMemoryFormatType = "BINARY"
// InMemoryFormatObject Data will be stored in deserialized form.
InMemoryFormatObject InMemoryFormatType = "OBJECT"
// InMemoryFormatNative Data will be stored in the map that uses Hazelcast's High-Density Memory Store feature.
InMemoryFormatNative InMemoryFormatType = "NATIVE"
)
type EventJournal struct {
// Capacity sets the capacity of the ringbuffer underlying the event journal.
// +kubebuilder:default:=10000
Capacity int32 `json:"capacity,omitempty"`
// TimeToLiveSeconds indicates how long the items remain in the event journal before they are expired.
// +kubebuilder:default:=0
TimeToLiveSeconds int32 `json:"timeToLiveSeconds,omitempty"`
}
type TieredStore struct {
// MemoryCapacity sets Memory tier capacity, i.e., how much main memory should this tier consume at most.
// +kubebuilder:default:="256M"
// +optional
MemoryCapacity *resource.Quantity `json:"memoryCapacity,omitempty"`
// diskDeviceName defines the name of the device for a given disk tier.
// +required
DiskDeviceName string `json:"diskDeviceName,omitempty"`
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// Map is the Schema for the maps API
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.state",description="Current state of the Map Config"
// +kubebuilder:printcolumn:name="Hazelcast-Resource",type="string",priority=1,JSONPath=".spec.hazelcastResourceName",description="Name of the Hazelcast resource that this resource is created for"
// +kubebuilder:printcolumn:name="Message",type="string",priority=1,JSONPath=".status.message",description="Message for the current Map Config"
type Map struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// +required
Spec MapSpec `json:"spec"`
// +optional
Status MapStatus `json:"status,omitempty"`
}
func (m *Map) MapName() string {
if m.Spec.Name != "" {
return m.Spec.Name
}
return m.Name
}
//+kubebuilder:object:root=true
// MapList contains a list of Map
type MapList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Map `json:"items"`
}
func (ml *MapList) GetItems() []client.Object {
l := make([]client.Object, 0, len(ml.Items))
for _, item := range ml.Items {
l = append(l, client.Object(&item))
}
return l
}
var (
EncodeMaxSizePolicy = map[MaxSizePolicyType]int32{
MaxSizePolicyPerNode: 0,
MaxSizePolicyPerPartition: 1,
MaxSizePolicyUsedHeapPercentage: 2,
MaxSizePolicyUsedHeapSize: 3,
MaxSizePolicyFreeHeapPercentage: 4,
MaxSizePolicyFreeHeapSize: 5,
MaxSizePolicyUsedNativeMemorySize: 6,
MaxSizePolicyUsedNativeMemoryPercentage: 7,
MaxSizePolicyFreeNativeMemorySize: 8,
MaxSizePolicyFreeNativeMemoryPercentage: 9,
MaxSizePolicyEntryCount: 10,
}
EncodeEvictionPolicyType = map[EvictionPolicyType]int32{
EvictionPolicyLRU: 0,
EvictionPolicyLFU: 1,
EvictionPolicyNone: 2,
EvictionPolicyRandom: 3,
}
EncodeIndexType = map[IndexType]int32{
IndexTypeSorted: 0,
IndexTypeHash: 1,
IndexTypeBitmap: 2,
}
EncodeUniqueKeyTransition = map[UniqueKeyTransition]int32{
UniqueKeyTransitionObject: 0,
UniqueKeyTransitionLong: 1,
UniqueKeyTransitionRAW: 2,
}
EncodeInMemoryFormat = map[InMemoryFormatType]int32{
InMemoryFormatBinary: 0,
InMemoryFormatObject: 1,
InMemoryFormatNative: 2,
}
)
func init() {
SchemeBuilder.Register(&Map{}, &MapList{})
}