Skip to content

Commit 22ca908

Browse files
authored
Merge pull request #107 from bgokden/develop
Deletion of unused datasets
2 parents a32fdc3 + eb09b38 commit 22ca908

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

data/data.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func (dt *Data) Close() error {
113113
}
114114
}
115115
// return dt.DB.Close()
116+
dt.DeletePath()
116117
return nil
117118
}
118119

@@ -123,6 +124,23 @@ func (dt *Data) DeletePath() error {
123124
return nil
124125
}
125126

127+
// Check if dataset is active
128+
func (dt *Data) CheckIfActive() bool {
129+
if dt.N > 0 {
130+
return true
131+
}
132+
if dt.Sources != nil && len(dt.Sources.Items()) > 0 {
133+
sourceList := dt.Sources.Items()
134+
for _, sourceItem := range sourceList { // Assumption is that random map runs are random enough
135+
source := sourceItem.Object.(DataSource)
136+
if source.GetDataInfo().N > 0 {
137+
return true
138+
}
139+
}
140+
}
141+
return false
142+
}
143+
126144
// Run runs statistical calculation regularly
127145
func (dt *Data) Run() error {
128146
if atomic.LoadInt32(&dt.Runs) >= 1 {

data/dataset.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,20 @@ func (dts *Dataset) LoadIndex() error {
189189

190190
func (dts *Dataset) ReloadRuns() error {
191191
itemList := dts.DataList.Items()
192-
for _, itemInterface := range itemList {
192+
removeList := make([]string, 0, len(itemList))
193+
for key, itemInterface := range itemList {
193194
if item, ok := itemInterface.Object.(*Data); ok {
194-
go item.Run()
195+
if item.CheckIfActive() {
196+
go item.Run()
197+
} else {
198+
item.Close()
199+
removeList = append(removeList, key)
200+
}
195201
}
196202
}
203+
for _, key := range removeList {
204+
dts.DataList.Delete(key)
205+
}
197206
return nil
198207
}
199208

kubernetes.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ spec:
4444
strategy:
4545
type: RollingUpdate
4646
rollingUpdate:
47-
maxUnavailable: 10%
47+
maxUnavailable: 5%
4848
maxSurge: 1
4949
selector:
5050
matchLabels:
@@ -56,7 +56,7 @@ spec:
5656
spec:
5757
containers:
5858
- name: veri
59-
image: berkgokden/veri:v0.0.103
59+
image: berkgokden/veri:v0.0.104
6060
args: ["serve", "--services=veriservice:10000"]
6161
imagePullPolicy: IfNotPresent
6262
ports:

0 commit comments

Comments
 (0)