Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
char-1ee committed Jan 29, 2024
1 parent 88ed5f7 commit 2ab9059
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 20 deletions.
1 change: 1 addition & 0 deletions cri/firecracker/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (c *coordinator) orchLoadInstance(ctx context.Context, snap *snapshotting.S
ctxTimeout, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()

logger.Debug("FIXME: temp pass same lastVmID")
resp, _, err := c.orch.LoadSnapshot(ctxTimeout, vmID, vmID, snap)
if err != nil {
logger.WithError(err).Error("failed to load VM")
Expand Down
2 changes: 1 addition & 1 deletion ctriface/failing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestStartSnapStop(t *testing.T) {
err = orch.StopSingleVM(ctx, vmID)
require.NoError(t, err, "Failed to stop VM")

_, _, err = orch.LoadSnapshot(ctx, "", vmID, snap)
_, _, err = orch.LoadSnapshot(ctx, "1", vmID, snap)
require.NoError(t, err, "Failed to load snapshot of VM")

_, err = orch.ResumeVM(ctx, vmID)
Expand Down
11 changes: 5 additions & 6 deletions ctriface/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (o *Orchestrator) StartVMWithEnvironment(ctx context.Context, vmID, imageNa
}
logger.Debugf("TEST: show to-reg snapStat: %+v", stateCfg)
logger.Debugf("TEST: show socket path: %s", resp.GetSocketPath())
if err := o.memoryManager.RegisterVM(stateCfg); err != nil {
if err := o.memoryManager.RegisterVM(stateCfg, false, ""); err != nil {
return nil, nil, errors.Wrap(err, "failed to register VM with memory manager")
// NOTE (Plamen): Potentially need a defer(DeregisteVM) here if RegisterVM is not last to execute
}
Expand Down Expand Up @@ -451,7 +451,7 @@ func (o *Orchestrator) CreateSnapshot(ctx context.Context, vmID string, snap *sn
}

// LoadSnapshot Loads a snapshot of a VM
func (o *Orchestrator) LoadSnapshot(ctx context.Context, snapVmID string, vmID string, snap *snapshotting.Snapshot) (_ *StartVMResponse, _ *metrics.Metric, retErr error) {
func (o *Orchestrator) LoadSnapshot(ctx context.Context, lastVmID string, vmID string, snap *snapshotting.Snapshot) (_ *StartVMResponse, _ *metrics.Metric, retErr error) {
var (
loadSnapshotMetric *metrics.Metric = metrics.NewMetric()
tStart time.Time
Expand Down Expand Up @@ -507,13 +507,13 @@ func (o *Orchestrator) LoadSnapshot(ctx context.Context, snapVmID string, vmID s
if o.GetUPFEnabled() {
logger.Debug("TEST: UPF is enabled")
conf.MemBackend.BackendType = uffdBackend
conf.MemBackend.BackendPath, err = o.memoryManager.GetUPFSockPath(snapVmID)
conf.MemBackend.BackendPath, err = o.memoryManager.GetUPFSockPath(lastVmID, true)
logger.Debugf("TEST: the upf socket: %s", conf.MemBackend.BackendPath)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to get UPF socket path for uffd backend")
}

if err := o.memoryManager.FetchState(snapVmID); err != nil {
if err := o.memoryManager.FetchState(lastVmID); err != nil {
return nil, nil, err
}
}
Expand Down Expand Up @@ -569,12 +569,11 @@ func (o *Orchestrator) LoadSnapshot(ctx context.Context, snapVmID string, vmID s
WorkingSetPath: o.getWorkingSetFile(vmID),
InstanceSockAddr: newUPFSockPath,
}
if err := o.memoryManager.RegisterVM(stateCfg); err != nil {
if err := o.memoryManager.RegisterVM(stateCfg, true, vmID); err != nil {
logger.Error(err, "failed to register new VM with memory manager")
}



if activateErr = o.memoryManager.Activate(vmID); activateErr != nil {
logger.Warn("Failed to activate VM in the memory manager", activateErr)
}
Expand Down
14 changes: 8 additions & 6 deletions ctriface/manual_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestSnapLoad(t *testing.T) {

vmID = "2"

_, _, err = orch.LoadSnapshot(ctx, vmID, vmID, snap)
_, _, err = orch.LoadSnapshot(ctx, "1", vmID, snap)
require.NoError(t, err, "Failed to load snapshot of VM")

_, err = orch.ResumeVM(ctx, vmID)
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestSnapLoadMultiple(t *testing.T) {

vmID = "4"

_, _, err = orch.LoadSnapshot(ctx, vmID, vmID, snap)
_, _, err = orch.LoadSnapshot(ctx, "3", vmID, snap)
require.NoError(t, err, "Failed to load snapshot of VM")

_, err = orch.ResumeVM(ctx, vmID)
Expand All @@ -163,7 +163,7 @@ func TestSnapLoadMultiple(t *testing.T) {

vmID = "5"

_, _, err = orch.LoadSnapshot(ctx, vmID, vmID, snap)
_, _, err = orch.LoadSnapshot(ctx, "4", vmID, snap)
require.NoError(t, err, "Failed to load snapshot of VM")

_, err = orch.ResumeVM(ctx, vmID)
Expand Down Expand Up @@ -234,10 +234,11 @@ func TestParallelSnapLoad(t *testing.T) {
err = orch.StopSingleVM(ctx, vmID)
require.NoError(t, err, "Failed to offload VM, "+vmID)

lastVmID := vmID
vmIDInt, _ := strconv.Atoi(vmID)
vmID = strconv.Itoa(vmIDInt + 1)

_, _, err = orch.LoadSnapshot(ctx, vmID, vmID, snap)
_, _, err = orch.LoadSnapshot(ctx, lastVmID, vmID, snap)
require.NoError(t, err, "Failed to load snapshot of VM, "+vmID)

_, err = orch.ResumeVM(ctx, vmID)
Expand Down Expand Up @@ -357,9 +358,10 @@ func TestParallelPhasedSnapLoad(t *testing.T) {
defer vmGroup.Done()
vmID := fmt.Sprintf("%d", i+vmIDBase)
snap := snapshotting.NewSnapshot(vmID, "/fccd/snapshots", testImageName)
lastVmID := vmID
vmIDInt, _ := strconv.Atoi(vmID)
vmID = strconv.Itoa(vmIDInt + 1)
_, _, err := orch.LoadSnapshot(ctx, vmID, vmID, snap)
_, _, err := orch.LoadSnapshot(ctx, lastVmID, vmID, snap)
require.NoError(t, err, "Failed to load snapshot of VM, "+vmID)
}(i)
}
Expand Down Expand Up @@ -482,7 +484,7 @@ func TestRemoteSnapLoad(t *testing.T) {

snap := snapshotting.NewSnapshot(revision, remoteSnapshotsDir, testImageName)

_, _, err = orch.LoadSnapshot(ctx, vmID, vmID, snap)
_, _, err = orch.LoadSnapshot(ctx, "36", vmID, snap)
require.NoError(t, err, "Failed to load remote snapshot of VM")

_, err = orch.ResumeVM(ctx, vmID)
Expand Down
11 changes: 6 additions & 5 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,12 @@ func (f *Function) AddInstance() *metrics.Metric {

if f.isSnapshotReady {
var resp *ctriface.StartVMResponse

// resp, metr = f.LoadInstance(f.getVMID())
snapVmID := fmt.Sprintf("%s-%d", f.fID, f.lastInstanceID - 1)

lastVmID := fmt.Sprintf("%s-%d", f.fID, f.lastInstanceID - 1)
currVmID := f.getVMID()
resp, metr = f.LoadInstance(snapVmID, currVmID)
resp, metr = f.LoadInstance(lastVmID, currVmID)

f.guestIP = resp.GuestIP
f.vmID = f.getVMID()
f.lastInstanceID++
Expand Down Expand Up @@ -482,7 +483,7 @@ func (f *Function) CreateInstanceSnapshot() {

// LoadInstance Loads a new instance of the function from its snapshot and resumes it
// The tap, the shim and the vmID remain the same
func (f *Function) LoadInstance(snapVmID string, vmID string) (*ctriface.StartVMResponse, *metrics.Metric) {
func (f *Function) LoadInstance(lastVmID string, vmID string) (*ctriface.StartVMResponse, *metrics.Metric) {
logger := log.WithFields(log.Fields{"fID": f.fID})

logger.Debug("Loading instance")
Expand All @@ -495,7 +496,7 @@ func (f *Function) LoadInstance(snapVmID string, vmID string) (*ctriface.StartVM
log.Panic(err)
}

resp, loadMetr, err := orch.LoadSnapshot(ctx, snapVmID, vmID, snap)
resp, loadMetr, err := orch.LoadSnapshot(ctx, lastVmID, vmID, snap)
if err != nil {
log.Panic(err)
}
Expand Down
37 changes: 35 additions & 2 deletions memory/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type MemoryManager struct {
sync.Mutex
MemoryManagerCfg
instances map[string]*SnapshotState // Indexed by vmID
origins map[string]string
}

// NewMemoryManager Initializes a new memory manager
Expand All @@ -62,12 +63,13 @@ func NewMemoryManager(cfg MemoryManagerCfg) *MemoryManager {
m := new(MemoryManager)
m.instances = make(map[string]*SnapshotState)
m.MemoryManagerCfg = cfg
m.origins = make(map[string]string)

return m
}

// RegisterVM Registers a VM within the memory manager
func (m *MemoryManager) RegisterVM(cfg SnapshotStateCfg) error {
func (m *MemoryManager) RegisterVM(cfg SnapshotStateCfg, isSnapshotReady bool, originID string) error {
m.Lock()
defer m.Unlock()

Expand All @@ -86,6 +88,10 @@ func (m *MemoryManager) RegisterVM(cfg SnapshotStateCfg) error {
state := NewSnapshotState(cfg)

m.instances[vmID] = state
// if isSnapshotReady {
// logger.Debugf("TEST: register current vmID %s with originID %s", vmID, originID)
// m.origins[vmID] = originID
// }

return nil
}
Expand Down Expand Up @@ -130,7 +136,17 @@ func (m *MemoryManager) Activate(vmID string) error {
m.Lock()

logger.Debug("TEST: Activate: fetch snapstate by vmID for UFFD")

// originID, ok := m.origins[vmID]

// if !ok {
// logger.Debug("TEST: not loaded from snapshot")
// }

// state, ok = m.instances[originID]

state, ok = m.instances[vmID]

if !ok {
m.Unlock()
logger.Error("VM not registered with the memory manager")
Expand Down Expand Up @@ -178,6 +194,12 @@ func (m *MemoryManager) FetchState(vmID string) error {

m.Lock()

// originID, ok := m.origins[vmID]
// if !ok {
// logger.Debug("TEST: not loaded from snapshot")
// }
// state, ok = m.instances[originID]

state, ok = m.instances[vmID]
if !ok {
m.Unlock()
Expand Down Expand Up @@ -352,13 +374,24 @@ func (m *MemoryManager) GetUPFLatencyStats(vmID string) ([]*metrics.Metric, erro
return state.latencyMetrics, nil
}

func (m *MemoryManager) GetUPFSockPath(vmID string) (string, error) {
func (m *MemoryManager) GetUPFSockPath(vmID string, isSnapshotReady bool) (string, error) {
logger := log.WithFields(log.Fields{"vmID": vmID})

logger.Debug("Get the path of firecracker unix domain socket")

m.Lock()

// id := ""
// if isSnapshotReady {
// logger.Debugf("TEST: to find originID by vmID %s", vmID)
// originID, ok := m.origins[vmID]
// if !ok {
// logger.Debug("TEST: not loaded from snapshot")
// }
// id = originID
// }
// state, ok := m.instances[id]

state, ok := m.instances[vmID]
if !ok {
m.Unlock()
Expand Down

0 comments on commit 2ab9059

Please sign in to comment.