Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions drsm/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,38 @@ import (

func (d *Drsm) podDownDetected() {
logger.DrsmLog.Infoln("started Pod Down goroutine")

for p := range d.podDown {
logger.DrsmLog.Infof("pod Down detected %v", p)
// Given Pod find out current Chunks owned by this POD
pd := d.podMap[p]

// Safely get pod entry
d.podMapMutex.RLock()
pd, found := d.podMap[p]
d.podMapMutex.RUnlock()

if !found || pd == nil {
logger.DrsmLog.Warnf("pod %s not found in podMap", p)
continue
}

// Copy chunk IDs while holding read lock
pd.mu.RLock()
chunkIDs := make([]int32, 0, len(pd.podChunks))
for k := range pd.podChunks {
d.globalChunkTblMutex.Lock()
chunkIDs = append(chunkIDs, k)
}
pd.mu.RUnlock()

// Process chunks without holding pod lock
for _, k := range chunkIDs {

d.globalChunkTblMutex.RLock()
c, found := d.globalChunkTbl[k]
d.globalChunkTblMutex.Unlock()
d.globalChunkTblMutex.RUnlock()

logger.DrsmLog.Debugf("found: %v chunk: %v", found, c)
if found {

if found && c != nil {
go c.claimChunk(d, pd.PodId.PodName)
}
}
Expand Down
21 changes: 15 additions & 6 deletions drsm/drsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ type chunk struct {
}

type podData struct {
PodId PodId `bson:"podId,omitempty" json:"podId,omitempty"`
Timestamp time.Time `bson:"time,omitempty" json:"time,omitempty"`
PrevTimestamp time.Time `bson:"-" json:"-"`
podChunks map[int32]*chunk `bson:"-" json:"-"` // chunkId to Chunk
PodId PodId
Timestamp time.Time
PrevTimestamp time.Time

mu sync.RWMutex
podChunks map[int32]*chunk
}

type Drsm struct {
Expand Down Expand Up @@ -77,14 +79,21 @@ func (d *Drsm) ConstuctDrsm(opt *Options) {
}
d.resourceValidCb = opt.ResourceValidCb
}

d.chunkIdRange = 1 << (d.resIdSize - 10)
logger.DrsmLog.Debugf("chunkId in the range of 0 to %v", d.chunkIdRange)

d.localChunkTbl = make(map[int32]*chunk)
d.globalChunkTbl = make(map[int32]*chunk)
d.podMap = make(map[string]*podData)
d.podDown = make(chan string, 10)
d.scanChunks = make(map[int32]*chunk)
d.globalChunkTblMutex = sync.Mutex{}

d.podDown = make(chan string, 10)

// No explicit initialization required, but fine to keep
d.globalChunkTblMutex = sync.RWMutex{}
d.podMapMutex = sync.RWMutex{}

d.initIpam(opt)

// connect to DB
Expand Down
10 changes: 9 additions & 1 deletion httpwrapper/httpwrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"time"

"github.com/5GC-DEV/util-cdac/logger"
"github.com/pkg/errors"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
Expand Down Expand Up @@ -57,10 +58,17 @@ func NewHttp2Server(bindAddr string, preMasterSecretLogPath string, handler http
return nil, errors.New("server needs handler to handle request")
}

h2Server := &http2.Server{
/*h2Server := &http2.Server{
// TODO: extends the idle time after re-use openapi client
IdleTimeout: 1 * time.Millisecond,
}*/
h2Server := &http2.Server{
IdleTimeout: 60 * time.Second,
}
logger.UtilLog.Infof(
"HTTP2 IdleTimeout=%v",
h2Server.IdleTimeout,
)
server := &http.Server{
Addr: bindAddr,
Handler: h2c.NewHandler(handler, h2Server),
Expand Down
49 changes: 49 additions & 0 deletions middleware/3gpp_Sbi_Request_Info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package middleware

import (
"net/http"
"sync"

"github.com/5GC-DEV/util-cdac/logger"
"github.com/gin-gonic/gin"
)

var requestCache sync.Map

func IdempotencyMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {

if c.Request.Method != http.MethodPost {
c.Next()
return
}

requestInfo := c.GetHeader("3gpp-Sbi-Request-Info")

if requestInfo != "" {
logger.UtilLog.Infof(
"Received idempotency key=%s method=%s path=%s",
requestInfo,
c.Request.Method,
c.Request.URL.Path,
)
}

if requestInfo == "" {
c.Next()
return
}

if _, exists := requestCache.Load(requestInfo); exists {
c.JSON(http.StatusConflict, gin.H{
"error": "duplicate request detected",
})
c.Abort()
return
}

requestCache.Store(requestInfo, true)

c.Next()
}
}