@@ -7,7 +7,16 @@ import (
7
7
"sync"
8
8
)
9
9
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
+ )
11
20
12
21
/*
13
22
OpSet represents the set of Ops that have been merged in an OpQueue,
@@ -61,20 +70,20 @@ type OpQueue struct {
61
70
ctx context.Context
62
71
can context.CancelFunc
63
72
64
- height int
73
+ depth int
65
74
width int
66
75
q * list.List
67
76
entries map [ID ]* OpSet
68
77
}
69
78
70
- func NewOpQueue (height , width int ) * OpQueue {
79
+ func NewOpQueue (depth , width int ) * OpQueue {
71
80
cond := sync .NewCond (& sync.Mutex {})
72
81
myctx , can := context .WithCancel (context .Background ())
73
82
q := & OpQueue {
74
83
cond : cond ,
75
84
ctx : myctx ,
76
85
can : can ,
77
- height : height ,
86
+ depth : depth ,
78
87
width : width ,
79
88
q : list .New (),
80
89
entries : map [ID ]* OpSet {},
@@ -95,7 +104,7 @@ func (q *OpQueue) Close() {
95
104
q .can ()
96
105
}
97
106
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.
99
108
func (q * OpQueue ) Len () int {
100
109
q .cond .L .Lock ()
101
110
defer q .cond .L .Unlock ()
@@ -112,8 +121,8 @@ func (q *OpQueue) Enqueue(id ID, op *Op) error {
112
121
q .cond .L .Lock ()
113
122
defer q .cond .L .Unlock ()
114
123
115
- if q .q .Len () >= q .height {
116
- return ErrQueueSaturated
124
+ if q .q .Len () >= q .depth {
125
+ return ErrQueueSaturatedDepth
117
126
}
118
127
119
128
set , ok := q .entries [id ]
@@ -142,7 +151,7 @@ func (q *OpQueue) Enqueue(id ID, op *Op) error {
142
151
}
143
152
144
153
if len (set .Ops ()) >= q .width {
145
- return ErrQueueSaturated
154
+ return ErrQueueSaturatedWidth
146
155
}
147
156
148
157
set .append (op )
0 commit comments