-
Notifications
You must be signed in to change notification settings - Fork 33
/
macentry.go
46 lines (39 loc) · 1.29 KB
/
macentry.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
package pool_manager
import "time"
func (m macEntry) isDummyEntry() bool {
return m.instanceName == tempVmName && m.macInstanceKey == tempVmInterface
}
func (m macEntry) hasPendingTransaction() bool {
return m.transactionTimestamp != nil
}
// hasReadyTransaction checks if the transaction TS recorded on the mac entry has passed the last
// timestamp annotation that persisted in the vm instance, signalling that we need to update this entry.
func (m macEntry) hasReadyTransaction(lastPersistentTime *time.Time) bool {
if !m.hasPendingTransaction() {
return false
}
return !m.transactionTimestamp.After(*lastPersistentTime)
}
func (m macEntry) resetTransaction() macEntry {
return macEntry{
instanceName: m.instanceName,
macInstanceKey: m.macInstanceKey,
transactionTimestamp: nil,
}
}
func (m macEntry) setTransaction(timestamp *time.Time) macEntry {
return macEntry{
instanceName: m.instanceName,
macInstanceKey: m.macInstanceKey,
transactionTimestamp: timestamp,
}
}
func (m macEntry) hasExpiredTransaction(waitTime int) (bool, error) {
if m.hasPendingTransaction() {
macTransactionExpiration := m.transactionTimestamp.Add(time.Duration(waitTime) * time.Second)
if now().After(macTransactionExpiration) {
return true, nil
}
}
return false, nil
}