Skip to content

Commit eb9f895

Browse files
author
Tim Middleton
committed
Minor doc update, near cache calc update
1 parent a2705c6 commit eb9f895

File tree

7 files changed

+109
-11
lines changed

7 files changed

+109
-11
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ generate-proto-v1: $(TOOLS_BIN)/protoc ## Generate Proto Files v1
244244
# ----------------------------------------------------------------------------------------------------------------------
245245
.PHONY: show-docs
246246
show-docs: ## Show the Documentation
247-
@echo "Serving documentation on http://localhost:6060/pkg/github.com/oracle/coherence-go-client/"
247+
@echo "Serving documentation on http://localhost:6060/pkg/github.com/oracle/coherence-go-client/v2"
248248
go install golang.org/x/tools/cmd/godoc@latest
249249
godoc -goroot $(GOROOT) -http=:6060
250250

@@ -421,7 +421,7 @@ getcopyright: ## Download copyright jar locally if necessary.
421421
$(TOOLS_BIN)/protoc:
422422
@mkdir -p $(TOOLS_BIN)
423423
./scripts/download-protoc.sh $(TOOLS_DIRECTORY)
424-
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30.0
424+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.33.0
425425
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0
426426

427427

coherence/event.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const (
6060
// MapEventType describes an event raised by a cache mutation.
6161
type MapEventType string
6262

63-
// MapLifecycleEventType describes an event that may be raised during the lifecycle
63+
// MapLifecycleEventType describes an event type that may be raised during the lifecycle
6464
// of a cache.
6565
type MapLifecycleEventType string
6666

@@ -159,8 +159,13 @@ func (se *sessionLifecycleEvent) String() string {
159159
return fmt.Sprintf("SessionLifecycleEvent{source=%v, format=%s}", se.Source(), se.Type())
160160
}
161161

162+
// MapLifecycleEvent describes an event that may be raised during the lifecycle
163+
// of a cache.
162164
type MapLifecycleEvent[K comparable, V any] interface {
165+
// Source returns the source of this MapLifecycleEvent.
163166
Source() NamedMap[K, V]
167+
168+
// Type returns the MapLifecycleEventType for this MapLifecycleEvent.
164169
Type() MapLifecycleEventType
165170
}
166171

@@ -186,22 +191,39 @@ func (l *mapLifecycleEvent[K, V]) Source() NamedMap[K, V] {
186191
return l.source
187192
}
188193

189-
// String returns a string representation of a MapLifecycleEvent.
194+
// String returns a string representation of a [MapLifecycleEvent].
190195
func (l *mapLifecycleEvent[K, V]) String() string {
191196
return fmt.Sprintf("MapLifecycleEvent{source=%v, type=%s}", l.Source().GetCacheName(), l.Type())
192197
}
193198

194-
// MapEvent an event which indicates that the content of the NamedMap or
195-
// NamedCache has changed (i.e., an entry has been added, updated, and/or
199+
// MapEvent an event which indicates that the content of the [NamedMap] or
200+
// [NamedCache] has changed (i.e., an entry has been added, updated, and/or
196201
// removed).
197202
type MapEvent[K comparable, V any] interface {
203+
// Source returns the source of this MapEvent.
198204
Source() NamedMap[K, V]
205+
206+
// Key returns the key of the entry for which this event was raised.
199207
Key() (*K, error)
208+
209+
// OldValue returns the old value, if any, of the entry for which this event
210+
// was raised.
200211
OldValue() (*V, error)
212+
213+
// NewValue returns the new value, if any, of the entry for which this event
214+
// was raised.
201215
NewValue() (*V, error)
216+
217+
// Type returns the MapEventType for this MapEvent.
202218
Type() MapEventType
219+
220+
// IsExpired returns true if the event was generated from an expiry event. Only valid for gRPC v1 connections.
203221
IsExpired() (bool, error)
222+
223+
// IsPriming returns true if the event is a priming event. Only valid for gRPC v1 connections.
204224
IsPriming() (bool, error)
225+
226+
// IsSynthetic returns true if the event is a synthetic event. Only valid for gRPC v1 connections.
205227
IsSynthetic() (bool, error)
206228
}
207229

coherence/localcache.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type localCache[K comparable, V any] interface {
4343
GetStats() CacheStats
4444
}
4545

46-
// CacheStats defines various statics for near caches.
46+
// CacheStats contains various statistics for near caches.
4747
type CacheStats interface {
4848
GetCacheHits() int64 // the number of entries served from the near cache
4949
GetCacheMisses() int64 // the number of entries that had to be retrieved from the cluster
@@ -479,7 +479,8 @@ func (l *localCacheImpl[K, V]) String() string {
479479
// updateEntrySize updates the cacheMemory size based upon a local entry. The sign indicates to either remove or add.
480480
func (l *localCacheImpl[K, V]) updateEntrySize(entry *localCacheEntry[K, V], sign int) {
481481
l.updateCacheMemory(int64(sign)*(int64(unsafe.Sizeof(entry.key))+int64(unsafe.Sizeof(entry.value))+
482-
(int64(unsafe.Sizeof(entry.ttl)))+(int64(unsafe.Sizeof(entry.insertTime)))) + (int64(unsafe.Sizeof(entry.lastAccess))))
482+
(int64(unsafe.Sizeof(entry.ttl)))+(int64(unsafe.Sizeof(entry.insertTime)))) +
483+
(int64(unsafe.Sizeof(entry.lastAccess))) + int64(unsafe.Sizeof(entry)))
483484
}
484485

485486
func formatMemory(bytesValue int64) string {

coherence/queue_events.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,16 @@ func (l *queueLifecycleEvent[V]) String() string {
5757
// QueueLifecycleListener allows registering callbacks to be notified when lifecycle events
5858
// (truncated, released or destroyed) occur against a [NamedQueue].
5959
type QueueLifecycleListener[V any] interface {
60+
// OnAny registers a callback that will be notified when any [NamedQueue] event occurs.
6061
OnAny(callback func(QueueLifecycleEvent[V])) QueueLifecycleListener[V]
62+
63+
// OnDestroyed registers a callback that will be notified when a [NamedQueue] is destroyed.
6164
OnDestroyed(callback func(QueueLifecycleEvent[V])) QueueLifecycleListener[V]
65+
66+
// OnTruncated registers a callback that will be notified when a [Queue] is truncated.
6267
OnTruncated(callback func(QueueLifecycleEvent[V])) QueueLifecycleListener[V]
68+
69+
// OnReleased registers a callback that will be notified when a [NamedQueue] is released.
6370
OnReleased(callback func(QueueLifecycleEvent[V])) QueueLifecycleListener[V]
6471
getEmitter() *eventEmitter[QueueLifecycleEventType, QueueLifecycleEvent[V]]
6572
}
@@ -89,7 +96,7 @@ func (q *queueLifecycleListener[V]) OnReleased(callback func(QueueLifecycleEvent
8996
return q.on(QueueReleased, callback)
9097
}
9198

92-
// OnTruncated registers a callback that will be notified when a [NamedMap] is truncated.
99+
// OnTruncated registers a callback that will be notified when a [Queue] is truncated.
93100
func (q *queueLifecycleListener[V]) OnTruncated(callback func(QueueLifecycleEvent[V])) QueueLifecycleListener[V] {
94101
return q.on(QueueTruncated, callback)
95102
}
@@ -98,7 +105,7 @@ func (q *queueLifecycleListener[V]) getEmitter() *eventEmitter[QueueLifecycleEve
98105
return q.emitter
99106
}
100107

101-
// OnAny registers a callback that will be notified when any [NamedMap] event occurs.
108+
// OnAny registers a callback that will be notified when any [NamedQueue] event occurs.
102109
func (q *queueLifecycleListener[V]) OnAny(callback func(QueueLifecycleEvent[V])) QueueLifecycleListener[V] {
103110
return q.OnTruncated(callback).OnDestroyed(callback).OnReleased(callback)
104111
}

coherence/serializers.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* https://oss.oracle.com/licenses/upl.
55
*/
@@ -28,8 +28,13 @@ type mathValue[T any] struct {
2828

2929
// Serializer defines how to serialize/ de-serialize objects.
3030
type Serializer[T any] interface {
31+
// Serialize serializes an object of type T and returns the []byte representation.
3132
Serialize(object T) ([]byte, error)
33+
34+
// Deserialize deserialized an object and returns the correct type of T.
3235
Deserialize(data []byte) (*T, error)
36+
37+
// Format returns the format used for the serializer.
3338
Format() string
3439
}
3540

@@ -111,6 +116,7 @@ func (s JSONSerializer[T]) Deserialize(data []byte) (*T, error) {
111116
return &zeroValue, fmt.Errorf("invalid serialization prefix %v", data[0])
112117
}
113118

119+
// Format returns the format used for the serializer.
114120
func (s JSONSerializer[T]) Format() string {
115121
return s.format
116122
}

coherence/v1client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,19 +843,22 @@ func (m *streamManagerV1) putGenericRequest(ctx context.Context, reqType pb1.Nam
843843
return unwrapBytes(result)
844844
}
845845

846+
// BinaryKeyAndValue is an internal type exported only for serialization.
846847
type BinaryKeyAndValue struct {
847848
Key []byte
848849
Value []byte
849850
Err error
850851
Cookie []byte
851852
}
852853

854+
// BinaryKey is an internal type exported only for serialization.
853855
type BinaryKey struct {
854856
Key []byte
855857
Err error
856858
Cookie []byte
857859
}
858860

861+
// BinaryValue is an internal type exported only for serialization.
859862
type BinaryValue struct {
860863
Value []byte
861864
Err error

test/e2e/standalone/near_cache_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
"github.com/oracle/coherence-go-client/v2/coherence/filters"
1414
"github.com/oracle/coherence-go-client/v2/coherence/processors"
1515
"github.com/oracle/coherence-go-client/v2/test/utils"
16+
"log"
1617
"math"
18+
"strconv"
1719
"testing"
1820
"time"
1921
)
@@ -583,6 +585,63 @@ func TestNearCachePruneFactor(t *testing.T) {
583585
g.Expect(coherence.GetNearCachePruneFactor[int, string](namedCache)).To(gomega.Equal(float32(0.8)))
584586
}
585587

588+
// TestNearCacheComparison runs tests to compare near and normal cache and outputs size and memory usage.
589+
func TestNearCacheComparison(t *testing.T) {
590+
g := gomega.NewWithT(t)
591+
session, err := utils.GetSession()
592+
g.Expect(err).ShouldNot(gomega.HaveOccurred())
593+
defer session.Close()
594+
595+
const maxValues = 2_000
596+
597+
nearCacheOptions := &coherence.NearCacheOptions{HighUnits: maxValues * 2}
598+
namedCache, err := coherence.GetNamedCache[string, string](session, "no-near-cache")
599+
g.Expect(err).ShouldNot(gomega.HaveOccurred())
600+
601+
namedCacheNear, err := coherence.GetNamedCache[string, string](session, "near-cache", coherence.WithNearCache(nearCacheOptions))
602+
g.Expect(err).ShouldNot(gomega.HaveOccurred())
603+
604+
g.Expect(namedCache.Clear(ctx)).ShouldNot(gomega.HaveOccurred())
605+
g.Expect(namedCacheNear.Clear(ctx)).ShouldNot(gomega.HaveOccurred())
606+
607+
values := make(map[string]string, 0)
608+
609+
// populate the map
610+
for i := 1; i <= maxValues; i++ {
611+
kv := strconv.Itoa(i)
612+
values[kv] = kv
613+
}
614+
615+
log.Printf("Insert %v entries into caches", maxValues)
616+
617+
g.Expect(namedCache.PutAll(ctx, values)).ShouldNot(gomega.HaveOccurred())
618+
g.Expect(namedCacheNear.PutAll(ctx, values)).ShouldNot(gomega.HaveOccurred())
619+
620+
log.Println("Start", maxValues, "gets on normal cache")
621+
start := time.Now()
622+
for i := 1; i <= maxValues; i++ {
623+
kv := strconv.Itoa(i)
624+
_, err = namedCache.Get(ctx, kv)
625+
g.Expect(err).ShouldNot(gomega.HaveOccurred())
626+
}
627+
628+
log.Printf("Time to get %v from normal cache is %v", maxValues, time.Since(start))
629+
630+
for j := 1; j <= 2; j++ {
631+
log.Printf("Run %v of get %v gets on near cache", j, maxValues)
632+
start = time.Now()
633+
for i := 1; i <= maxValues; i++ {
634+
kv := strconv.Itoa(i)
635+
_, err = namedCacheNear.Get(ctx, kv)
636+
g.Expect(err).ShouldNot(gomega.HaveOccurred())
637+
}
638+
639+
log.Printf("Run: %v time to get %v from near cache is %v", j, maxValues, time.Since(start))
640+
}
641+
642+
log.Println(namedCacheNear.GetNearCacheStats())
643+
}
644+
586645
// TestInvalidNearCacheOptions runs tests to ensure that we can't create a named cache/map with invalid options.
587646
func TestInvalidNearCacheOptions(t *testing.T) {
588647
var (

0 commit comments

Comments
 (0)