Skip to content

Commit ed10fb0

Browse files
authored
Merge pull request #1 from lytics/opQueue-uniq-errors-depth-vs-width
adding errors that are different for depth vs width
2 parents 27227cd + 14e69ab commit ed10fb0

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ queue is full during enqueue.
9292
| |
9393
| |
9494
| v
95-
Height | +-----+ +-----+ +-----+
95+
Depth | +-----+ +-----+ +-----+
9696
| |ID +---->ID +---->ID |
9797
| |424 | |424 | |424 |
9898
| +-----+ +-----+ +-----+

opqueue.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ import (
77
"sync"
88
)
99

10-
var ErrQueueSaturated = fmt.Errorf("queue is saturated")
10+
var (
11+
// ErrQueueSaturatedDepth is the error returned when the queue has reached
12+
// it's max queue depth
13+
ErrQueueSaturatedDepth = fmt.Errorf("queue is saturated (depth)")
14+
15+
// ErrQueueSaturatedWidth is the error returned when a OpSet (aka a row) with
16+
// in the queue has reached it's max width. This happens when one submits
17+
// many duplicate IDs.
18+
ErrQueueSaturatedWidth = fmt.Errorf("queue is saturated (width)")
19+
)
1120

1221
/*
1322
OpSet represents the set of Ops that have been merged in an OpQueue,
@@ -61,20 +70,20 @@ type OpQueue struct {
6170
ctx context.Context
6271
can context.CancelFunc
6372

64-
height int
73+
depth int
6574
width int
6675
q *list.List
6776
entries map[ID]*OpSet
6877
}
6978

70-
func NewOpQueue(height, width int) *OpQueue {
79+
func NewOpQueue(depth, width int) *OpQueue {
7180
cond := sync.NewCond(&sync.Mutex{})
7281
myctx, can := context.WithCancel(context.Background())
7382
q := &OpQueue{
7483
cond: cond,
7584
ctx: myctx,
7685
can: can,
77-
height: height,
86+
depth: depth,
7887
width: width,
7988
q: list.New(),
8089
entries: map[ID]*OpSet{},
@@ -95,7 +104,7 @@ func (q *OpQueue) Close() {
95104
q.can()
96105
}
97106

98-
// Len returns the number of uniq IDs in the queue, that is the height of the queue.
107+
// Len returns the number of uniq IDs in the queue, that is the depth of the queue.
99108
func (q *OpQueue) Len() int {
100109
q.cond.L.Lock()
101110
defer q.cond.L.Unlock()
@@ -112,8 +121,8 @@ func (q *OpQueue) Enqueue(id ID, op *Op) error {
112121
q.cond.L.Lock()
113122
defer q.cond.L.Unlock()
114123

115-
if q.q.Len() >= q.height {
116-
return ErrQueueSaturated
124+
if q.q.Len() >= q.depth {
125+
return ErrQueueSaturatedDepth
117126
}
118127

119128
set, ok := q.entries[id]
@@ -142,7 +151,7 @@ func (q *OpQueue) Enqueue(id ID, op *Op) error {
142151
}
143152

144153
if len(set.Ops()) >= q.width {
145-
return ErrQueueSaturated
154+
return ErrQueueSaturatedWidth
146155
}
147156

148157
set.append(op)

0 commit comments

Comments
 (0)