I got a map map[uint64]*target
with struct target
:
type target struct {
sync.RWMutex
path string
backupPath string
inode uint64
waitingChildred []*target
}
After deleting an entry using delete(mymap, some_uint64)
, the map remains with one entry left (the entry I wanted to delete) which points to nil
. I have no idea what is happening so debugging is quite difficult..
pre execution:
m: <*main.inodeMap>(0xc00015a960)
-> RWMutex: <sync.RWMutex>
-> _map <map[uint64]*main.target>
-> 2363967: <*main.target>(0xc000060420)
...
-> 2365973: <*main.target>(0xc0001024e0)
...
inumber: 2363967
executing: delete(m._map, inumber)
post execution:
m: <*main.inodeMap>(0xc00015a960)
-> RWMutex: <sync.RWMutex>
-> _map <map[uint64]*main.target>
-> 2363967: nil <*main.target>
I expected it to be a pointer issue but the map entries point to different addresses so that shouldn't be the problem.
EDIT: Thats the method I'm using:
func (m *inodeMap) deleteTarget(inumber uint64) error {
t, ok := m.getTargetByInode(inumber)
if !ok {
return fmt.Errorf("...")
}
if len(t.waitingChildred) > 0 {
return fmt.Errorf("...")
}
m.Lock()
delete(m._map, inumber)
m.Unlock()
return nil
}
That's the maps sturct
type inodeMap struct {
sync.RWMutex
_map map[uint64]*target
}