github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/tables/block_test.go (about)

     1  // Copyright 2021 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package tables
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/container/types"
    21  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers"
    22  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/handle"
    23  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/index"
    24  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/tables/indexwrapper"
    25  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/tables/updates"
    26  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils"
    27  	"github.com/stretchr/testify/assert"
    28  )
    29  
    30  func TestGetActiveRow(t *testing.T) {
    31  	defer testutils.AfterTest(t)()
    32  	ts1 := types.BuildTS(1, 0)
    33  	ts2 := types.BuildTS(2, 0)
    34  	mvcc := updates.NewMVCCHandle(nil)
    35  	// blk := &dataBlock{
    36  	// 	mvcc: mvcc,
    37  	// }
    38  	b := &baseBlock{
    39  		RWMutex: mvcc.RWMutex,
    40  		mvcc:    mvcc,
    41  	}
    42  	mnode := &memoryNode{
    43  		block: b,
    44  	}
    45  	blk := &ablock{baseBlock: b}
    46  
    47  	mnode.Ref()
    48  	n := NewNode(mnode)
    49  	blk.node.Store(n)
    50  
    51  	// appendnode1 [0,1)
    52  	an1, _ := mvcc.AddAppendNodeLocked(nil, 0, 1)
    53  	an1.Start = ts1
    54  	an1.Prepare = ts1
    55  	an1.End = ts1
    56  
    57  	// appendnode1 [1,2)
    58  	an2, _ := mvcc.AddAppendNodeLocked(nil, 1, 2)
    59  	an2.Start = ts1
    60  	an2.Prepare = ts1
    61  	an2.End = ts1
    62  
    63  	// index uint8(1)-0,1
    64  	vec := containers.MakeVector(types.T_int8.ToType(), false)
    65  	vec.Append(int8(1))
    66  	vec.Append(int8(1))
    67  	idx := indexwrapper.NewPkMutableIndex(types.T_int8.ToType())
    68  	keysCtx := &index.KeysCtx{
    69  		Keys: vec,
    70  	}
    71  	keysCtx.SelectAll()
    72  	err := idx.BatchUpsert(keysCtx, 0)
    73  	assert.NoError(t, err)
    74  	blk.node.Load().MustMNode().pkIndex = idx
    75  
    76  	node := blk.node.Load().MustMNode()
    77  	// row, err := blk.GetActiveRow(int8(1), ts2)
    78  	row, err := blk.getInMemoryRowByFilter(node, ts2, handle.NewEQFilter(int8(1)))
    79  	assert.NoError(t, err)
    80  	assert.Equal(t, uint32(1), row)
    81  
    82  	//abort appendnode2
    83  	an2.Aborted = true
    84  
    85  	row, err = blk.getInMemoryRowByFilter(node, ts2, handle.NewEQFilter(int8(1)))
    86  	// row, err = blk.GetActiveRow(int8(1), ts2)
    87  	assert.NoError(t, err)
    88  	assert.Equal(t, uint32(0), row)
    89  }