aboutsummaryrefslogtreecommitdiffstats
path: root/src/mongo.go
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2024-08-06 14:31:31 +0800
committerWe-unite <3205135446@qq.com>2024-08-06 14:31:31 +0800
commitf4655e64a1461c22ad7a3871375269915a743f40 (patch)
tree535e8d77431337bc431df85cfc2b675464395879 /src/mongo.go
parent78de56b9f2d862bbdac8a02a72dd95500b7ef83e (diff)
downloadgodo-f4655e64a1461c22ad7a3871375269915a743f40.tar.gz
godo-f4655e64a1461c22ad7a3871375269915a743f40.zip
Expand connector buffer, put all file info into db
This commit I make several changes, reasons are as follows: - Expand netlink connector buffer size. Originally it uses only one page of mem, but sometimes it causes "no enough buffer" errno, or the socket is blocked long time. Now it's 20 pages. - All file infos are thrown into database. As the last commit co- mment, There's 2 tables, "fds" and "files". When a file discriptor is closed, the info in fds will be found, delete, and put into the "file" table with its close time. Left questions: - The netlink connector is always found blocked without any reasons. Fix it, or replace the golang-coded connector with C program? The key is why it's blocked. Maybe it's in the kernel src code. - sometimes audit still losts info(not too much). For instance, I use vim in the docker to change hello.c, the hello.c may be opened but no close info recvd. Or, the swap file of vim, such as .hello.c.swp or .hello.c.swx is not closed. What's more, the hello.c is never written, but swap files are. May vim write to swap files, and replace the origin file? Let's check it. - Besides, when a pid exits, we should check its file discriptors and close them all.
Diffstat (limited to 'src/mongo.go')
-rw-r--r--src/mongo.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/mongo.go b/src/mongo.go
index 3a23131..764f877 100644
--- a/src/mongo.go
+++ b/src/mongo.go
@@ -78,6 +78,13 @@ func (mc *mongoClient) Finddoc(filter bson.M) ([]bson.M, error) {
78 return results, err 78 return results, err
79} 79}
80 80
81func (mc *mongoClient) FindOneAndDelete(filter bson.M) (bson.M, error) {
82 res := mc.col.FindOneAndDelete(context.Background(), filter)
83 var result bson.M
84 err := res.Decode(&result)
85 return result, err
86}
87
81func (mc *mongoClient) Drop() error { 88func (mc *mongoClient) Drop() error {
82 return mc.col.Drop(context.Background()) 89 return mc.col.Drop(context.Background())
83} 90}
@@ -94,11 +101,14 @@ func (mc *mongoClient) Disconnect() error {
94 return nil 101 return nil
95} 102}
96 103
97func (mc *mongoClient) GetLock() { 104func (mc *mongoClient) GetLock() bool {
98 for i := 0; i < 20000; { 105 for i := 0; i < 200000; {
99 if !mc.Mutex.TryLock() { 106 if !mc.Mutex.TryLock() {
100 i++ 107 i++
108 } else {
109 return true
101 } 110 }
102 } 111 }
103 fmt.Printf("Die...\n") 112 fmt.Printf("Die...\n")
113 return false
104} 114}