mirror of
https://github.com/gotoeasy/glogcenter.git
synced 2025-09-15 12:58:34 +08:00
日志仓删除前检查
This commit is contained in:
parent
8923babbc8
commit
5b7330d007
10
README.md
10
README.md
@ -91,12 +91,18 @@ docker run -d -p 8080:8080 -v /glc:/glogcenter gotoeasy/glc
|
||||
|
||||
## 更新履历
|
||||
|
||||
### 进行中的开发版本`latest`
|
||||
### 开发版`latest`
|
||||
|
||||
- [ ] TODO
|
||||
- [ ] TODO
|
||||
- [ ] TODO
|
||||
|
||||
### 版本`0.4.0`
|
||||
|
||||
- [x] 添加相应版本的`maven`公共仓库包,`java`项目日志可推至`RabbitMQ`
|
||||
- [x] 添加`RabbitMQ`简单模式消费者,开启后能从`RabbitMQ`获取日志
|
||||
- [x] 添加服务接口`/glc/v1/log/add`,接收`JSON`格式日志以便后续扩展
|
||||
- [x] 日志可分仓,可查看、删除
|
||||
- [x] 页面添加日志仓管理功能,支持查看、删除等操作
|
||||
|
||||
### 版本`0.3.0`
|
||||
|
||||
|
||||
19
glc/ldb/status/storage_status.go
Normal file
19
glc/ldb/status/storage_status.go
Normal file
@ -0,0 +1,19 @@
|
||||
package status
|
||||
|
||||
var mapStorageStatus map[string]string // 日志仓是否正在使用
|
||||
|
||||
func init() {
|
||||
mapStorageStatus = make(map[string]string)
|
||||
}
|
||||
|
||||
func UpdateStorageStatus(name string, open bool) {
|
||||
if open {
|
||||
mapStorageStatus[name] = "1"
|
||||
} else {
|
||||
delete(mapStorageStatus, name)
|
||||
}
|
||||
}
|
||||
|
||||
func IsStorageOpening(name string) bool {
|
||||
return mapStorageStatus[name] == "1"
|
||||
}
|
||||
@ -8,6 +8,7 @@ package indexdoc
|
||||
import (
|
||||
"glc/cmn"
|
||||
"glc/conf"
|
||||
"glc/ldb/status"
|
||||
"glc/onexit"
|
||||
"log"
|
||||
"sync"
|
||||
@ -78,7 +79,8 @@ func NewDocIndexStorage(storeName string) *DocIndexStorage { // 存储器,文
|
||||
panic(err)
|
||||
}
|
||||
store.leveldb = db
|
||||
mapStorage[cacheName] = store // 缓存起来
|
||||
status.UpdateStorageStatus(storeName, true) // 更新状态:当前日志仓打开
|
||||
mapStorage[cacheName] = store // 缓存起来
|
||||
|
||||
// 逐秒判断,若闲置超时则自动关闭
|
||||
go store.autoCloseWhenMaxIdle()
|
||||
|
||||
@ -8,6 +8,7 @@ package indexword
|
||||
import (
|
||||
"glc/cmn"
|
||||
"glc/conf"
|
||||
"glc/ldb/status"
|
||||
"glc/ldb/storage/indexdoc"
|
||||
"glc/onexit"
|
||||
"log"
|
||||
@ -83,8 +84,9 @@ func NewWordIndexStorage(storeName string) *WordIndexStorage { // 存储器,
|
||||
panic(err)
|
||||
}
|
||||
store.leveldb = db
|
||||
store.loadIndexedCount() // 加载已建索引件数
|
||||
mapStorage[cacheName] = store // 缓存起来
|
||||
store.loadIndexedCount() // 加载已建索引件数
|
||||
status.UpdateStorageStatus(storeName, true) // 更新状态:当前日志仓打开
|
||||
mapStorage[cacheName] = store // 缓存起来
|
||||
|
||||
// 逐秒判断,若闲置超时则自动关闭
|
||||
go store.autoCloseWhenMaxIdle()
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"errors"
|
||||
"glc/cmn"
|
||||
"glc/conf"
|
||||
"glc/ldb/status"
|
||||
"glc/ldb/storage/indexword"
|
||||
"glc/ldb/tokenizer"
|
||||
"glc/onexit"
|
||||
@ -85,8 +86,9 @@ func NewLogDataStorage(storeName string, subPath string) *LogDataStorage { //
|
||||
panic(err)
|
||||
}
|
||||
store.leveldb = db
|
||||
store.loadMetaData() // 初始化件数等信息
|
||||
mapStorage[cacheName] = store // 缓存起来
|
||||
store.loadMetaData() // 初始化件数等信息
|
||||
status.UpdateStorageStatus(storeName, true) // 更新状态:当前日志仓打开
|
||||
mapStorage[cacheName] = store // 缓存起来
|
||||
|
||||
// 消费就绪
|
||||
go store.readyGo()
|
||||
@ -269,12 +271,13 @@ func (s *LogDataStorage) Close() {
|
||||
}
|
||||
|
||||
s.closing = true
|
||||
s.wg.Wait() // 等待通道清空
|
||||
s.saveMetaData() // 保存件数等元信息
|
||||
s.wg.Add(1) // 通道消息计数
|
||||
s.storeChan <- nil // 通道正在在阻塞等待接收,给个nil让它接收后关闭
|
||||
s.leveldb.Close() // 走到这里时没有db操作了,可以关闭
|
||||
mapStorage[s.storeName] = nil // 设空,下回GetStorage时自动再创建
|
||||
s.wg.Wait() // 等待通道清空
|
||||
s.saveMetaData() // 保存件数等元信息
|
||||
s.wg.Add(1) // 通道消息计数
|
||||
s.storeChan <- nil // 通道正在在阻塞等待接收,给个nil让它接收后关闭
|
||||
s.leveldb.Close() // 走到这里时没有db操作了,可以关闭
|
||||
mapStorage[s.storeName] = nil // 设空,下回GetStorage时自动再创建
|
||||
status.UpdateStorageStatus(s.storeName, false) // 更新状态:当前日志仓关闭
|
||||
|
||||
log.Println("关闭LogDataStorage:", s.storeName+cmn.PathSeparator()+s.subPath)
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"glc/gweb"
|
||||
"glc/ldb/status"
|
||||
"glc/ldb/sysmnt"
|
||||
"log"
|
||||
)
|
||||
@ -15,11 +16,15 @@ func StorageListController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
// 删除指定日志仓
|
||||
func StorageDeleteController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
name := req.GetFormParameter("storeName")
|
||||
if status.IsStorageOpening(name) {
|
||||
return gweb.Error500("日志仓 " + name + " 正在使用,不能删除")
|
||||
}
|
||||
|
||||
err := sysmnt.DeleteStorage(name)
|
||||
if err != nil {
|
||||
msg := err.Error()
|
||||
log.Println("日志仓", name, "删除失败", msg)
|
||||
return gweb.Error500("日志仓 " + name + " 正在使用中,无法删除")
|
||||
return gweb.Error500("日志仓 " + name + " 正在使用,不能删除")
|
||||
}
|
||||
return gweb.Ok()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user