Skip to content

Commit

Permalink
fix load test shell (#63)
Browse files Browse the repository at this point in the history
* ignore files

* fix load test sh

* fix load system index panic

* fixed panic when delete document

* fix panic when delete index

* format check index exist

* maxResults use front params
  • Loading branch information
hengfeiyang committed Jan 12, 2022
1 parent 2e62092 commit 006236c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -20,4 +20,4 @@ __debug_bin

main
dist/

cmd/zinc
5 changes: 3 additions & 2 deletions load_test.sh
@@ -1,4 +1,5 @@
# curl -v -u admin:Complexpass#123 -POST -H "Content-Type: application/json" -d @load_test_data_2.json http://localhost:4080/es/books/_doc

# hey -n 20000 -c 50 -m POST -H "Content-Type: application/json" -D load_test_data_1.json http://localhost:4080/books/_doc
hey -n 20000 -c 50 -m POST -H "Content-Type: application/json" -D load_test_data_2.json http://localhost:4080/books/_doc

# -a "admin:Complexpass#123" ==> -H "Authorization: Basic YWRtaW46Q29tcGxleHBhc3MjMTIz"
hey -n 2000 -c 10 -H "Authorization: Basic YWRtaW46Q29tcGxleHBhc3MjMTIz" -m POST -H "Content-Type: application/json" -D load_test_data_2.json http://localhost:4080/es/books/_doc
9 changes: 4 additions & 5 deletions pkg/core/LoadIndexes.go
Expand Up @@ -18,15 +18,14 @@ func LoadZincSystemIndexes() (map[string]*Index, error) {
log.Print("Loading system indexes...")

IndexList := make(map[string]*Index)
var err error

for _, systemIndex := range systemIndexList {
IndexList[systemIndex], err = NewIndex(systemIndex)
IndexList[systemIndex].IndexType = "system"
tempIndex, err := NewIndex(systemIndex)
if err != nil {
log.Print(err.Error())
log.Print("Error loading system index: ", systemIndex, " : ", err.Error())
return nil, err
}
IndexList[systemIndex] = tempIndex
IndexList[systemIndex].IndexType = "system"
log.Print("Index loaded: " + systemIndex)
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/handlers/DeleteDocument.go
Expand Up @@ -12,6 +12,11 @@ func DeleteDocument(c *gin.Context) {
indexName := c.Param("target")
query_id := c.Param("id")

if !core.IndexExists(indexName) {
c.JSON(http.StatusBadRequest, gin.H{"error": "index not exist"})
return
}

// log.Printf("deleet document indexName:%[1]s, query_id:%[2]s", indexName, query_id)

bdoc := bluge.NewDocument(query_id)
Expand Down
35 changes: 20 additions & 15 deletions pkg/handlers/DeleteIndex.go
Expand Up @@ -14,6 +14,11 @@ import (
func DeleteIndex(c *gin.Context) {
indexName := c.Param("indexName")

if !core.IndexExists(indexName) {
c.JSON(http.StatusBadRequest, gin.H{"error": "index not exist"})
return
}

// 1. Close the index writer
core.ZINC_INDEX_LIST[indexName].Writer.Close()

Expand All @@ -28,21 +33,21 @@ func DeleteIndex(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
} else {
// 4. Delete the index mapping
bdoc := bluge.NewDocument(indexName)
err = core.ZINC_SYSTEM_INDEX_LIST["_index_mapping"].Writer.Delete(bdoc.ID())

if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
} else {
c.JSON(http.StatusOK, gin.H{
"message": "Deleted",
"index": indexName,
})
}
return
}

// 4. Delete the index mapping
bdoc := bluge.NewDocument(indexName)
err = core.ZINC_SYSTEM_INDEX_LIST["_index_mapping"].Writer.Delete(bdoc.ID())

if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
} else {
c.JSON(http.StatusOK, gin.H{
"message": "Deleted",
"index": indexName,
})
}
}
10 changes: 5 additions & 5 deletions pkg/handlers/Search.go
Expand Up @@ -12,18 +12,18 @@ func SearchIndex(c *gin.Context) {

indexName := c.Param("target")

if !core.IndexExists(indexName) {
c.JSON(http.StatusBadRequest, gin.H{"error": "index not exist"})
return
}

// fmt.Println("Got search request for index: ", indexName)

var iQuery v1.ZincQuery

c.BindJSON(&iQuery)

index := core.ZINC_INDEX_LIST[indexName]
if index == nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "index not exist"})
return
}

res, errS := index.Search(iQuery)

if errS != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/AllDocuments.go
Expand Up @@ -13,7 +13,7 @@ func AllDocuments(iQuery v1.ZincQuery) (bluge.SearchRequest, error) {

query := bluge.NewBooleanQuery().AddMust(dateQuery).AddMust(allquery)

iQuery.MaxResults = 20
// iQuery.MaxResults = 20

searchRequest := buildRequest(iQuery, query)

Expand Down
2 changes: 2 additions & 0 deletions web/.gitignore
@@ -1,6 +1,8 @@
.DS_Store
node_modules
/dist
/yarn.lock


/tests/e2e/videos/
/tests/e2e/screenshots/
Expand Down

0 comments on commit 006236c

Please sign in to comment.