Repository: VictoriaMetrics/VictoriaMetrics
Pull request #655 (2020-07-27 03:10:05)

lib/storage: metaindexRow use memroy more efficiently
due to memory align the metaindexRow structure use 64-byte pre object.
```
Meta Index Row: 64 byte
  TSID:              24 byte
  BlockHeadersCount: 4  byte
  blank padding:     4  byte
  MinTimestamp:      8  byte
  MaxTimestamp:      8  byte
  IndexBlcokOffset:  8  byte
  IndexBlcokSize:    4  byte
  blank padding:     4  byte
```

this PR removes the blank padding by changing the field order.

```
Meta Index Row: 56 byte
  TSID:              24 byte
  MinTimestamp:      8  byte
  MaxTimestamp:      8  byte
  IndexBlcokOffset:  8  byte
  BlockHeadersCount: 4  byte
  IndexBlcokSize:    4  byte
```

codecov[bot]: # [Codecov](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655?src=pr&el=h1) Report
> Merging [#655](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655?src=pr&el=desc) into [master](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/commit/edb1eca6f1db7ab2fdbf7e931a390d4d9ec30739&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655/graphs/tree.svg?width=650&height=150&src=pr&token=YND8dYVcXn)](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #655      +/-   ##
==========================================
- Coverage   68.30%   68.28%   -0.02%     
==========================================
  Files         159      159              
  Lines       21916    21916              
==========================================
- Hits        14970    14966       -4     
- Misses       5724     5728       +4     
  Partials     1222     1222              
```


| [Impacted Files](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [lib/storage/metaindex\_row.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655/diff?src=pr&el=tree#diff-bGliL3N0b3JhZ2UvbWV0YWluZGV4X3Jvdy5nbw==) | `67.90% <ø> (ø)` | |
| [app/vmselect/promql/transform.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655/diff?src=pr&el=tree#diff-YXBwL3Ztc2VsZWN0L3Byb21xbC90cmFuc2Zvcm0uZ28=) | `87.52% <100.00%> (+0.17%)` | :arrow_up: |
| [app/vmselect/promql/aggr\_incremental.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655/diff?src=pr&el=tree#diff-YXBwL3Ztc2VsZWN0L3Byb21xbC9hZ2dyX2luY3JlbWVudGFsLmdv) | `82.46% <0.00%> (-3.90%)` | :arrow_down: |
| [lib/mergeset/table.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655/diff?src=pr&el=tree#diff-bGliL21lcmdlc2V0L3RhYmxlLmdv) | `68.23% <0.00%> (+0.27%)` | :arrow_up: |
| [lib/storage/merge.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655/diff?src=pr&el=tree#diff-bGliL3N0b3JhZ2UvbWVyZ2UuZ28=) | `84.29% <0.00%> (+1.65%)` | :arrow_up: |
| [app/vmalert/remotewrite/remotewrite.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655/diff?src=pr&el=tree#diff-YXBwL3ZtYWxlcnQvcmVtb3Rld3JpdGUvcmVtb3Rld3JpdGUuZ28=) | `62.71% <0.00%> (+1.69%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655?src=pr&el=footer). Last update [894dcb7...b405253](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/655?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/app/vmagent/remotewrite/client.go b/app/vmagent/remotewrite/client.go
index 7dcadcdfe..77c92ebf6 100644
--- a/app/vmagent/remotewrite/client.go
+++ b/app/vmagent/remotewrite/client.go
@@ -182,6 +182,9 @@ func (c *client) runWorker() {
 }
 
 func (c *client) sendBlock(block []byte) {
+	retryDuration := time.Second
+
+again:
 	req, err := http.NewRequest("POST", c.remoteWriteURL, bytes.NewBuffer(block))
 	if err != nil {
 		logger.Panicf("BUG: unexected error from http.NewRequest(%q): %s", c.remoteWriteURL, err)
@@ -195,9 +198,6 @@ func (c *client) sendBlock(block []byte) {
 		req.Header.Set("Authorization", c.authHeader)
 	}
 
-	retryDuration := time.Second
-
-again:
 	startTime := time.Now()
 	resp, err := c.hc.Do(req)
 	c.requestDuration.UpdateDuration(startTime)
diff --git a/lib/storage/metaindex_row.go b/lib/storage/metaindex_row.go
index 8dc1dbdbd..ef93d5deb 100644
--- a/lib/storage/metaindex_row.go
+++ b/lib/storage/metaindex_row.go
@@ -16,10 +16,6 @@ type metaindexRow struct {
 	// TSID is the first TSID in the corresponding index block.
 	TSID TSID
 
-	// BlockHeadersCount is the number of block headers
-	// in the given index block.
-	BlockHeadersCount uint32
-
 	// MinTimestamp is the minimum timestamp in the given index block.
 	MinTimestamp int64
 
@@ -29,6 +25,10 @@ type metaindexRow struct {
 	// IndexBlockOffset is the offset of index block.
 	IndexBlockOffset uint64
 
+	// BlockHeadersCount is the number of block headers
+	// in the given index block.
+	BlockHeadersCount uint32
+
 	// IndexBlockSize is the size of compressed index block.
 	IndexBlockSize uint32
 }


Test patch:
diff --git a/lib/protoparser/prometheus/parser_test.go b/lib/protoparser/prometheus/parser_test.go
index d86a19fb4..6a2e0740f 100644
--- a/lib/protoparser/prometheus/parser_test.go
+++ b/lib/protoparser/prometheus/parser_test.go
@@ -180,6 +180,20 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
 			Timestamp: 789,
 		}},
 	})
+	f(`#                                    _                                            _
+#   ___ __ _ ___ ___  __ _ _ __   __| |_ __ __ _        _____  ___ __   ___  _ __| |_ ___ _ __
+`+"#  / __/ _` / __/ __|/ _` | '_ \\ / _` | '__/ _` |_____ / _ \\ \\/ / '_ \\ / _ \\| '__| __/ _ \\ '__|\n"+`
+# | (_| (_| \__ \__ \ (_| | | | | (_| | | | (_| |_____|  __/>  <| |_) | (_) | |  | ||  __/ |
+#  \___\__,_|___/___/\__,_|_| |_|\__,_|_|  \__,_|      \___/_/\_\ .__/ \___/|_|   \__\___|_|
+#                                                               |_|
+#
+# TYPE cassandra_token_ownership_ratio gauge
+cassandra_token_ownership_ratio 78.9`, &Rows{
+		Rows: []Row{{
+			Metric: "cassandra_token_ownership_ratio",
+			Value:  78.9,
+		}},
+	})
 
 	// Timestamp bigger than 1<<31
 	f("aaa 1123 429496729600", &Rows{