Example #1
0
// putNeedle overwriting is bug,  banned
func (h *HBaseClient) putNeedle(n *meta.Needle) (err error) {
	var (
		ks    []byte
		vbuf  = make([]byte, 4)
		cbuf  = make([]byte, 4)
		ubuf  = make([]byte, 8)
		exist bool
		c     *hbasethrift.THBaseServiceClient
	)
	if c, err = hbasePool.Get(); err != nil {
		log.Errorf("hbasePool.Get() error(%v)", err)
		return
	}
	ks = h.key(n.Key)
	if exist, err = c.Exists(_table, &hbasethrift.TGet{Row: ks}); err != nil {
		hbasePool.Put(c, true)
		return
	}
	if exist {
		hbasePool.Put(c, false)
		return errors.ErrNeedleExist
	}
	binary.BigEndian.PutUint32(vbuf, uint32(n.Vid))
	binary.BigEndian.PutUint32(cbuf, uint32(n.Cookie))
	binary.BigEndian.PutUint64(ubuf, uint64(time.Now().UnixNano()))
	if err = c.Put(_table, &hbasethrift.TPut{
		Row: ks,
		ColumnValues: []*hbasethrift.TColumnValue{
			&hbasethrift.TColumnValue{
				Family:    _familyBasic,
				Qualifier: _columnVid,
				Value:     vbuf,
			},
			&hbasethrift.TColumnValue{
				Family:    _familyBasic,
				Qualifier: _columnCookie,
				Value:     cbuf,
			},
			&hbasethrift.TColumnValue{
				Family:    _familyBasic,
				Qualifier: _columnUpdateTime,
				Value:     ubuf,
			},
		},
	}); err != nil {
		hbasePool.Put(c, true)
		return
	}
	hbasePool.Put(c, false)
	return
}
Example #2
0
// updateFile overwriting is bug,  banned
func (h *HBaseClient) updateFile(c *hbasethrift.THBaseServiceClient, bucket, filename, sha1 string) (err error) {
	var (
		ks   []byte
		ubuf = make([]byte, 8)
	)
	ks = []byte(filename)
	binary.BigEndian.PutUint64(ubuf, uint64(time.Now().UnixNano()))
	err = c.Put(h.tableName(bucket), &hbasethrift.TPut{
		Row: ks,
		ColumnValues: []*hbasethrift.TColumnValue{
			&hbasethrift.TColumnValue{
				Family:    _familyFile,
				Qualifier: _columnSha1,
				Value:     []byte(sha1),
			},
			&hbasethrift.TColumnValue{
				Family:    _familyFile,
				Qualifier: _columnUpdateTime,
				Value:     ubuf,
			},
		},
	})
	return
}
Example #3
0
// putFile overwriting is bug,  banned
func (h *HBaseClient) putFile(bucket string, f *meta.File) (err error) {
	var (
		ks    []byte
		kbuf  = make([]byte, 8)
		stbuf = make([]byte, 4)
		ubuf  = make([]byte, 8)
		exist bool
		c     *hbasethrift.THBaseServiceClient
	)
	if c, err = hbasePool.Get(); err != nil {
		log.Errorf("hbasePool.Get() error(%v)", err)
		return
	}
	ks = []byte(f.Filename)
	if exist, err = c.Exists(h.tableName(bucket), &hbasethrift.TGet{Row: ks}); err != nil {
		hbasePool.Put(c, true)
		return
	}
	if exist {
		hbasePool.Put(c, false)
		return errors.ErrNeedleExist
	}
	binary.BigEndian.PutUint64(kbuf, uint64(f.Key))
	binary.BigEndian.PutUint32(stbuf, uint32(f.Status))
	binary.BigEndian.PutUint64(ubuf, uint64(time.Now().UnixNano()))
	if err = c.Put(h.tableName(bucket), &hbasethrift.TPut{
		Row: ks,
		ColumnValues: []*hbasethrift.TColumnValue{
			&hbasethrift.TColumnValue{
				Family:    _familyFile,
				Qualifier: _columnKey,
				Value:     kbuf,
			},
			&hbasethrift.TColumnValue{
				Family:    _familyFile,
				Qualifier: _columnSha1,
				Value:     []byte(f.Sha1),
			},
			&hbasethrift.TColumnValue{
				Family:    _familyFile,
				Qualifier: _columnMine,
				Value:     []byte(f.Mine),
			},
			&hbasethrift.TColumnValue{
				Family:    _familyFile,
				Qualifier: _columnStatus,
				Value:     stbuf,
			},
			&hbasethrift.TColumnValue{
				Family:    _familyFile,
				Qualifier: _columnUpdateTime,
				Value:     ubuf,
			},
		},
	}); err != nil {
		hbasePool.Put(c, true)
		return
	}
	hbasePool.Put(c, false)
	return
}