/
mo_db_structs.go
164 lines (139 loc) · 6.88 KB
/
mo_db_structs.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
package mongostorage
const (
DefaultMongoURI string = "mongodb://localhost:27017"
DefaultMongoDatabaseName string = "nntp"
DefaultMongoCollection string = "articles"
DefaultMongoTimeout int64 = 15
DefaultDelQueue int = 1
DefaultDelWorker int = 1
DefaultDeleteBatchSize int = 1
DefaultInsQueue int = 1
DefaultInsWorker int = 1
DefaultInsertBatchSize int = 1
DefaultGetQueue int = 1
DefaultGetWorker int = 1
DefaultFlushTimer int64 = 1000
)
// Compression constants
const (
NOCOMP int = 0
GZIP_enc int = 1
ZLIB_enc int = 2
FLATE_enc int = 3
)
// Note: The default values provided above are recommended for most use cases.
// However, these values can be adjusted according to your specific requirements.
// Be cautious when modifying these settings, as improper adjustments might lead to suboptimal performance or resource utilization.
var (
Counter COUNTER
// _queue channels handle requests for read/get, delete and insert
Mongo_Reader_queue chan *MongoGetRequest
Mongo_Delete_queue chan *MongoDelRequest
Mongo_Insert_queue chan *MongoArticle
// pass a bool [true|false] to the UpDN_ channels and workers will start or stop
// external access via: mongostorage.UpDn_***_Worker_chan
UpDn_StopAll_Worker_chan = make(chan bool, 1)
UpDn_Reader_Worker_chan = make(chan bool, 1)
UpDn_Delete_Worker_chan = make(chan bool, 1)
UpDn_Insert_Worker_chan = make(chan bool, 1)
LOCK_UpDnScaler = make(chan struct{}, 1)
// internal channels to notify workers to stop
stop_reader_worker_chan = make(chan int, 1)
stop_delete_worker_chan = make(chan int, 1)
stop_insert_worker_chan = make(chan int, 1)
worker_status_chan = make(chan workerstatus, 65535)
READER string = "reader"
DELETE string = "delete"
INSERT string = "insert"
) // end var
type workerstatus struct {
wType string
status update
}
type update struct {
Did int
Bad int
Boot bool
Stop bool
}
// MongoStorageConfig represents the parameters for configuring MongoDB and worker goroutines.
// You can adjust the number of worker goroutines and queue sizes based on your application's requirements and available resources.
type MongoStorageConfig struct {
// MongoURI is a string representing the MongoDB connection URI.
// It should include the necessary authentication details and the address of the MongoDB server.
MongoURI string
// MongoDatabaseName is a string representing the name of the MongoDB database where the articles will be stored and retrieved from.
MongoDatabaseName string
// MongoCollection is a string representing the name of the collection within the database where the articles will be stored.
MongoCollection string
// MongoTimeout is an int64 value defining the timeout for a connection attempt to the MongoDB server.
// If the connection is not successful within this duration, it will time out.
MongoTimeout int64
// DelWorker is an integer specifying the number of worker goroutines to handle article deletions.
// It determines the level of concurrency for deletion operations.
// More DelWorker values can improve the speed at which articles are deleted from the database.
DelWorker int
// DelQueue is an integer specifying the size of the delete queue.
// It specifies how many delete requests can be buffered before the send operation blocks.
// If DelQueue is 0 or negative, a default value will be used.
// The DelQueue parameter sets the maximum number of article deletion requests that can be buffered before the worker goroutines start processing them.
DelQueue int
// InsWorker is an integer specifying the number of worker goroutines to handle article insertions.
// It determines the level of concurrency for insertion operations.
// This parameter controls the concurrency for insertion operations, allowing multiple articles to be inserted simultaneously.
InsWorker int
// InsQueue is an integer specifying the size of the insert queue.
// It specifies how many article insertion requests can be buffered before the send operation blocks.
// If InsQueue is 0 or negative, a default value will be used.
// The InsQueue parameter specifies the maximum number of article insertion requests that can be buffered in the queue before the worker goroutines process them.
// If the number of pending insertions exceeds this limit, the send operation on the Mongo_Insert_queue channel will block.
InsQueue int
// GetWorker is an integer specifying the number of worker goroutines to handle article reads.
// It determines the level of concurrency for read operations.
// This parameter controls the level of concurrency for read operations, enabling multiple read requests to be processed concurrently.
GetWorker int
// GetQueue is an integer specifying the size of the read queue.
// It specifies how many read requests can be buffered before the send operation blocks.
// If GetQueue is 0 or negative, a default value will be used.
// The GetQueue parameter defines the maximum length of the read request queue.
// When the number of read requests exceeds this limit, the send operation on the Mongo_Reader_queue channel will block until space becomes available.
GetQueue int
// TestAfterInsert is a boolean flag indicating whether to perform a test after an article insertion.
// The specific test details are not provided in the function, and the flag can be used for application-specific testing purposes.
TestAfterInsert bool
// DelBatch sets the number of MessageIDs a DeleteWorker will cache before deleting to batch into one process.
DelBatch int
// InsBatch sets the number of Articles an InsertWorker will cache before inserting to batch into one process.
InsBatch int
// FlushTimer represent the default time in milliseconds for flushing batched operations to MongoDB.
FlushTimer int64
} // end type MongoStorageConfig
type MongoArticles struct {
List []*MongoArticle
}
// MongoArticle represents an article stored in MongoDB.
type MongoArticle struct {
MessageID string `bson:"_id"`
Hash string `bson:"hash"`
Newsgroups []string `bson:"newsgroups"`
Head []byte `bson:"head"`
Headsize int `bson:"hs"`
Body []byte `bson:"body"`
Bodysize int `bson:"bs"`
Arrival int64 `bson:"at"`
HeadDate int64 `bson:"hd"`
Enc int `bson:"enc"`
Found bool
} // end type MongoArticle struct
// MongoGetRequest represents a read request for fetching articles from MongoDB.
type MongoGetRequest struct {
MessageIDs []string
STAT bool
RetChan chan []*MongoArticle
} // end type MongoGetRequest struct
// MongoDelRequest represents a delete request for deleting articles from MongoDB.
type MongoDelRequest struct {
MessageIDs []string
RetChan chan int64
} // end type MongoDelRequest struct
// EOF mo_db_structs.go