Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: guo-shaoge <shaoge1994@163.com>
  • Loading branch information
guo-shaoge committed May 9, 2021
1 parent 02e3245 commit a8e9931
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions util/checksum/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func (s *testChecksumSuite) TestChecksumWriter(c *check.C) {
buf.WriteString(testData)
}

// write 1000 bytes and flush
// Write 1000 bytes and flush.
w := NewWriter(f)
n, err := w.Write(buf.Bytes())
c.Assert(err, check.IsNil)
Expand All @@ -688,7 +688,7 @@ func (s *testChecksumSuite) TestChecksumWriter(c *check.C) {
c.Assert(err, check.IsNil)
checkFlushedData(c, f, 0, 1000, 1000, nil, buf.Bytes())

// all data flushed, so no data in cache.
// All data flushed, so no data in cache.
cacheOff := w.GetCacheDataOffset()
c.Assert(cacheOff, check.Equals, int64(1000))
}
Expand All @@ -715,7 +715,7 @@ func (s *testChecksumSuite) TestChecksumWriterAutoFlush(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(n, check.Equals, len(buf.Bytes()))

// this write will trigger flush
// This write will trigger flush.
n, err = w.Write([]byte("0"))
c.Assert(err, check.IsNil)
c.Assert(n, check.Equals, 1)
Expand Down
8 changes: 4 additions & 4 deletions util/chunk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ type ReaderWithCache struct {
cache []byte
}

// NewReaderWithCache returns a ReaderWithCache
// NewReaderWithCache returns a ReaderWithCache.
func NewReaderWithCache(r io.ReaderAt, cache []byte, cacheOff int64) *ReaderWithCache {
return &ReaderWithCache{
r: r,
Expand All @@ -390,7 +390,7 @@ func NewReaderWithCache(r io.ReaderAt, cache []byte, cacheOff int64) *ReaderWith
}
}

// ReadAt implements the ReadAt interface
// ReadAt implements the ReadAt interface.
func (r *ReaderWithCache) ReadAt(p []byte, off int64) (readCnt int, err error) {
readCnt, err = r.r.ReadAt(p, off)
if err != io.EOF {
Expand All @@ -407,7 +407,7 @@ func (r *ReaderWithCache) ReadAt(p []byte, off int64) (readCnt int, err error) {
// When got here, user input is not filled fully, so we need read data from cache.
err = nil
if readCnt == 0 {
// readCnt == 0 means all user requested data resides in r.cache
// 'readCnt == 0' means all user requested data resides in r.cache.
beg := off - r.cacheOff
if beg < 0 {
return readCnt, errors2.Trace(errors2.New("off must be greater than r.cacheOff when readCnt is 0"))
Expand All @@ -419,7 +419,7 @@ func (r *ReaderWithCache) ReadAt(p []byte, off int64) (readCnt int, err error) {
}
readCnt = copy(p, r.cache[beg:end])
} else {
// readCnt != 0 means only partial data of user requested resides in r.cache
// readCnt != 0 means only partial data of user requested resides in r.cache.
p = p[readCnt:]
end := len(p)
if end > len(r.cache) {
Expand Down
34 changes: 17 additions & 17 deletions util/chunk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ func (s *testChunkSuite) TestListInDiskWithChecksumAndEncrypt(c *check.C) {
testReaderWithCacheNoFlush(c)
}

// checksum layer data layout:
// 4 B: checksum of this segment
// 8 B: all columns' length, in the following example, we will only have one column
// Following diagram describes the testdata we use to test:
// 4 B: checksum of this segment.
// 8 B: all columns' length, in the following example, we will only have one column.
// 1012 B: data in file. because max length of each segment is 1024, so we only have 1020B for user payload.
//
// Data in File Data in mem cache
Expand All @@ -266,7 +266,7 @@ func testReaderWithCache(c *check.C) {
err := l.Add(chk)
c.Assert(err, check.IsNil)

// basic test for GetRow()
// Basic test for GetRow().
row, err := l.GetRow(RowPtr{0, 0})
c.Assert(err, check.IsNil)
c.Assert(row.GetDatumRow(field), check.DeepEquals, chk.GetRow(0).GetDatumRow(field))
Expand All @@ -277,59 +277,59 @@ func testReaderWithCache(c *check.C) {
}
checksumReader := NewReaderWithCache(checksum.NewReader(underlying), l.checksumWriter.GetCache(), l.checksumWriter.GetCacheDataOffset())

// read all data
// Read all data.
data := make([]byte, 1024)
// off is 8, because we want to ignore col length
// Offset is 8, because we want to ignore col length.
readCnt, err := checksumReader.ReadAt(data, 8)
c.Assert(err, check.IsNil)
c.Assert(readCnt, check.Equals, 1024)
c.Assert(reflect.DeepEqual(data, buf.Bytes()), check.IsTrue)

// only read data of mem cache
// Only read data of mem cache.
data = make([]byte, 1024)
readCnt, err = checksumReader.ReadAt(data, 1020)
c.Assert(err, check.Equals, io.EOF)
c.Assert(readCnt, check.Equals, 12)
c.Assert(reflect.DeepEqual(data[:12], buf.Bytes()[1012:]), check.IsTrue)

// read partial data of mem cache
// Read partial data of mem cache.
data = make([]byte, 1024)
readCnt, err = checksumReader.ReadAt(data, 1025)
c.Assert(err, check.Equals, io.EOF)
c.Assert(readCnt, check.Equals, 7)
c.Assert(reflect.DeepEqual(data[:7], buf.Bytes()[1017:]), check.IsTrue)

// read partial data from both file and mem cache
// Read partial data from both file and mem cache.
data = make([]byte, 1024)
readCnt, err = checksumReader.ReadAt(data, 1010)
c.Assert(err, check.Equals, io.EOF)
c.Assert(readCnt, check.Equals, 22)
c.Assert(reflect.DeepEqual(data[:22], buf.Bytes()[1002:]), check.IsTrue)

// off is too large, so no data is read
// Offset is too large, so no data is read.
data = make([]byte, 1024)
readCnt, err = checksumReader.ReadAt(data, 1032)
c.Assert(err, check.Equals, io.EOF)
c.Assert(readCnt, check.Equals, 0)
c.Assert(reflect.DeepEqual(data, make([]byte, 1024)), check.IsTrue)

// only read 1 byte from mem cache
// Only read 1 byte from mem cache.
data = make([]byte, 1024)
readCnt, err = checksumReader.ReadAt(data, 1031)
c.Assert(err, check.Equals, io.EOF)
c.Assert(readCnt, check.Equals, 1)
c.Assert(reflect.DeepEqual(data[:1], buf.Bytes()[1023:]), check.IsTrue)

// test user requested data is small
// only request 10 bytes
// Test user requested data is small.
// Only request 10 bytes.
data = make([]byte, 10)
readCnt, err = checksumReader.ReadAt(data, 1010)
c.Assert(err, check.IsNil)
c.Assert(readCnt, check.Equals, 10)
c.Assert(reflect.DeepEqual(data, buf.Bytes()[1002:1012]), check.IsTrue)
}

// here we test situations where size of data is small, so no data is flushed to disk
// Here we test situations where size of data is small, so no data is flushed to disk.
func testReaderWithCacheNoFlush(c *check.C) {
testData := "0123456789"

Expand All @@ -340,7 +340,7 @@ func testReaderWithCacheNoFlush(c *check.C) {
err := l.Add(chk)
c.Assert(err, check.IsNil)

// basic test for GetRow()
// Basic test for GetRow().
row, err := l.GetRow(RowPtr{0, 0})
c.Assert(err, check.IsNil)
c.Assert(row.GetDatumRow(field), check.DeepEquals, chk.GetRow(0).GetDatumRow(field))
Expand All @@ -351,9 +351,9 @@ func testReaderWithCacheNoFlush(c *check.C) {
}
checksumReader := NewReaderWithCache(checksum.NewReader(underlying), l.checksumWriter.GetCache(), l.checksumWriter.GetCacheDataOffset())

// read all data
// Read all data.
data := make([]byte, 1024)
// off is 8, because we want to ignore col length
// Offset is 8, because we want to ignore col length.
readCnt, err := checksumReader.ReadAt(data, 8)
c.Assert(err, check.Equals, io.EOF)
c.Assert(readCnt, check.Equals, len(testData))
Expand Down

0 comments on commit a8e9931

Please sign in to comment.