Skip to content

Commit

Permalink
Fix (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnu-liguobin authored Dec 10, 2023
1 parent b643e9b commit b06542b
Show file tree
Hide file tree
Showing 28 changed files with 35 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bitlap.common
//package org.bitlap.common

/*
import org.bitlap.common.utils.Range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bitlap.common.utils
//package org.bitlap.common.utils

/*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import scala.collection.mutable.ListBuffer

/** Prune time filter to push down
*/
type TimeFilterFun = (Long) => Boolean
type TimeFilterFun = Long => Boolean

case class PruneTimeFilterExpr(name: String, func: TimeFilterFun, expr: String)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.bitlap.core.sql.table.BitlapSqlDdlTable
import org.apache.calcite.DataContext
import org.apache.calcite.prepare.RelOptTableImpl
import org.apache.calcite.rel.RelNode
import org.apache.calcite.rel.hint.RelHint
import org.apache.calcite.rel.logical.LogicalTableScan
import org.apache.calcite.sql.`type`.SqlTypeName
import org.apache.calcite.sql.SqlOperator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.bitlap.core.sql.parser.ddl.user

import org.bitlap.core.sql.parser.{ BitlapSqlDdlCreateNode, BitlapSqlDdlNode }
import org.bitlap.core.sql.parser.BitlapSqlDdlNode
import org.bitlap.core.sql.parser.ddl.SqlShowCurrentDatabase

import org.apache.calcite.DataContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/
package org.bitlap.core.sql.parser.ddl.user

import org.bitlap.common.LiteralSQL._
import org.bitlap.common.utils.StringEx.*
import org.bitlap.core.sql.QueryContext
import org.bitlap.common.LiteralSQL.*
import org.bitlap.core.sql.parser.BitlapSqlDdlNode

import org.apache.calcite.DataContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import org.bitlap.core.sql.PruneTimeFilter
import org.apache.calcite.DataContext
import org.apache.calcite.linq4j.Enumerable
import org.apache.calcite.linq4j.Linq4j
import org.apache.calcite.rel.core.TableScan
import org.apache.calcite.rex.RexNode
import org.apache.calcite.util.ImmutableIntList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@
*/
package org.bitlap.server

import java.util.Vector as JVector
import java.util.concurrent.ConcurrentHashMap

import org.bitlap.common.exception._
import org.bitlap.common.exception.*
import org.bitlap.common.utils.StringEx
import org.bitlap.network.*
import org.bitlap.network.handles._
import org.bitlap.network.protocol.impl.*
import org.bitlap.server.config.*
import org.bitlap.server.session._
import org.bitlap.server.session.*

import com.alipay.sofa.jraft.*
import com.alipay.sofa.jraft.option.CliOptions
Expand Down Expand Up @@ -81,7 +76,7 @@ final class BitlapGlobalContext(
def isLeader: ZIO[Any, Throwable, Boolean] =
isStarted *> nodeRef.get.someOrFail(BitlapIllegalStateException("Cannot find a leader")).map(_.isLeader)

def getLeaderAddress(): Task[ServerAddress] =
def getLeaderOrRefresh(): Task[ServerAddress] =
for {
cliClientService <- cliClientServiceRef.get
peers = config.raftConfig.initialServerAddressList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*/
package org.bitlap.server

import scala.concurrent.duration.*

import org.bitlap.server.config.*
import org.bitlap.server.http.HttpRoutes
import org.bitlap.server.http.route._
import org.bitlap.server.http.service._
import org.bitlap.server.http.route.*
import org.bitlap.server.http.service.*
import org.bitlap.server.service.*
import org.bitlap.server.session.SessionManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.bitlap.server.raft.*

import com.alipay.sofa.jraft.Node
import com.alipay.sofa.jraft.option.NodeOptions
import com.typesafe.scalalogging.LazyLogging

import zio.{ Runtime as _, * }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@
*/
package org.bitlap.server.http

import scala.collection.mutable.ListBuffer

import org.bitlap.common.exception._
import org.bitlap.server.http.Response

import io.circe.*
import io.circe.generic.auto.*
import io.circe.syntax.EncoderOps
import sttp.tapir.{ Schema, SchemaType }
import sttp.tapir.Codec.JsonCodec
import sttp.tapir.json.circe.*
import sttp.tapir.ztapir.*
import zio.ZIO

/** Provide a custom decoder, encoder, schema for [[org.bitlap.common.exception.BitlapThrowable]].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
*/
package org.bitlap.server.http

import org.bitlap.common.exception._
import org.bitlap.common.exception.*

import io.circe.Encoder._
import sttp.model.{ headers => _, _ }
import sttp.tapir._
import sttp.model.{ headers as _, * }
import sttp.tapir.*
import sttp.tapir.json.circe.jsonBody
import sttp.tapir.server.interceptor.DecodeFailureContext
import sttp.tapir.server.interceptor.decodefailure.DefaultDecodeFailureHandler
import sttp.tapir.server.interceptor.decodefailure.DefaultDecodeFailureHandler.FailureMessages
import sttp.tapir.server.interceptor.exception._
import sttp.tapir.server.interceptor.exception.*
import sttp.tapir.server.model.ValuedEndpointOutput
import zio.Task

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,12 @@
*/
package org.bitlap.server.http

import org.bitlap.common.exception.*
import org.bitlap.server.http.route.*

import io.circe.generic.auto.*
import sttp.tapir.*
import sttp.tapir.generic.auto.*
import sttp.tapir.json.circe.*
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.server.interceptor.exception.ExceptionHandler
import sttp.tapir.server.interceptor.log.DefaultServerLog
import sttp.tapir.server.interceptor.reject.DefaultRejectHandler
import sttp.tapir.server.interceptor.reject.RejectHandler
import sttp.tapir.server.model.ValuedEndpointOutput
import sttp.tapir.server.ziohttp.{ ZioHttpInterpreter, ZioHttpServerOptions }
import sttp.tapir.server.ziohttp.*
import sttp.tapir.swagger.bundle.SwaggerInterpreter
import zio.*
import zio.http.HttpApp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.bitlap.server.http.model

import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
import java.util.Base64

inline val DefaultPassword = ""
Expand All @@ -32,7 +32,7 @@ final case class AccountInfo(
object AccountInfo:

def createCookieValue(username: String, password: String): String = {
val base64 = Base64.getEncoder.encode(s"Bearer $username:$password".getBytes(Charset.forName("utf8")))
val base64 = Base64.getEncoder.encode(s"Bearer $username:$password".getBytes(StandardCharsets.UTF_8))
new String(base64)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ package org.bitlap.server.http.route
import scala.collection.mutable.ListBuffer

import org.bitlap.common.exception.*
import org.bitlap.server.http._
import org.bitlap.server.http.*

import io.circe.*
import io.circe.generic.auto.*
import io.circe.syntax.EncoderOps
import sttp.model.StatusCode
import sttp.tapir.{ AnyEndpoint, Endpoint, Schema, SchemaType }
import sttp.tapir.Codec.JsonCodec
import sttp.tapir.json.circe.*
import sttp.tapir.server.interceptor.CustomiseInterceptors
import sttp.tapir.{ AnyEndpoint, Endpoint }
import sttp.tapir.ztapir.*
import zio.ZIO

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import org.bitlap.server.http.model.AccountInfo

import io.circe.*
import io.circe.generic.auto.*
import sttp.tapir.json.circe.*
import sttp.tapir.ztapir.*
import zio.ZIO

/** Abstract routes for bitlap security endpoints.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@
*/
package org.bitlap.server.http.route

import org.bitlap.common.exception._
import org.bitlap.server.BitlapGlobalContext
import org.bitlap.server.http.{ FormValidator, Response }
import org.bitlap.server.http.*
import org.bitlap.server.http.model.*
import org.bitlap.server.http.service.UserService
import org.bitlap.server.service.AccountAuthenticator

import io.circe.*
import io.circe.generic.auto.*
import sttp.model.HeaderNames.Authorization
import sttp.model.headers.CookieValueWithMeta
import sttp.tapir.{ ValidationResult, Validator }
import sttp.tapir.files.staticResourceGetServerEndpoint
import sttp.tapir.Validator
import sttp.tapir.generic.auto.*
import sttp.tapir.json.circe.*
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.ztapir.*
import sttp.tapir.ztapir.query
import zio.*

object UserRoute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
*/
package org.bitlap.server.http.service

import scala.util.control.NonFatal

import org.bitlap.common.BitlapLogging
import org.bitlap.common.exception.BitlapExceptions
import org.bitlap.common.extension.*
import org.bitlap.common.utils.StringEx
import org.bitlap.network.*
import org.bitlap.server.BitlapGlobalContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import org.bitlap.core.*
import org.bitlap.core.catalog.metadata.Database
import org.bitlap.core.sql.QueryExecution
import org.bitlap.network.enumeration.*
import org.bitlap.network.models.*
import org.bitlap.network.serde.BitlapSerde
import org.bitlap.server.config.BitlapConfigWrapper
import org.bitlap.server.http.model.AccountInfo
import org.bitlap.server.session.mapTo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package org.bitlap.server.service

import scala.util.control.NonFatal

import org.bitlap.common.exception.{ BitlapException, BitlapThrowable }
import org.bitlap.common.exception._
import org.bitlap.core.catalog.metadata.Database
import org.bitlap.network.*
import org.bitlap.network.enumeration.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.bitlap.server.service

import org.bitlap.common.exception.BitlapIllegalArgumentException
import org.bitlap.common.exception._
import org.bitlap.network.*
import org.bitlap.network.Driver.*
import org.bitlap.network.Driver.ZioDriver.ZDriverService
Expand Down Expand Up @@ -100,7 +100,7 @@ final class DriverGrpcServer(async: AsyncProtocol, globalContext: BitlapGlobalCo
.mapBoth(errorApplyFunc, _.toBGetResultSetMetadataResp)

override def getLeader(request: BGetLeaderReq, context: RequestContext): IO[StatusException, BGetLeaderResp] = {
val leaderAddress = globalContext.getLeaderAddress()
val leaderAddress = globalContext.getLeaderOrRefresh()
leaderAddress.flatMap { ld =>
if ld == null || ld.port <= 0 || ld.ip == null || ld.ip.isEmpty then {
ZIO.fail(BitlapIllegalArgumentException(s"Invalid leader address for requestId: ${request.requestId}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@
*/
package org.bitlap.server.session

import java.sql.*
import java.util.concurrent.{ CountDownLatch, TimeUnit }
import java.util.concurrent.*

import scala.collection.mutable

import org.bitlap.common.exception.DataFormatException
import org.bitlap.core.*
import org.bitlap.core.sql.QueryExecution
import org.bitlap.network.enumeration.*
import org.bitlap.network.enumeration.{ OperationState, OperationType }
import org.bitlap.network.enumeration.OperationState.*
import org.bitlap.network.handles.OperationHandle
import org.bitlap.network.models.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@
*/
package org.bitlap.server.session

import java.util.Date
import java.util.Vector as JVector
import java.util.{ Date, Vector as JVector }
import java.util.concurrent.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.*

import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.jdk.CollectionConverters.CollectionHasAsScala

import org.bitlap.common.exception._
import org.bitlap.common.exception.*
import org.bitlap.core.catalog.metadata.Database
import org.bitlap.network.enumeration._
import org.bitlap.network.enumeration.*
import org.bitlap.network.handles.*
import org.bitlap.network.models.GetInfoValue
import org.bitlap.server.BitlapGlobalContext
import org.bitlap.server.config.BitlapConfigWrapper
import org.bitlap.server.service.AccountAuthenticator

import zio.{ System as _, * }
Expand Down Expand Up @@ -132,7 +129,7 @@ final class SessionManager(
sessionStoreMap <- sessions.get
sessionState <- Ref.make(new AtomicBoolean(true))
sessionCreateTime <- Ref.make(new AtomicLong(System.currentTimeMillis()))
defaultSessionConf <- Ref.make(mutable.Map(sessionConf.toList: _*))
defaultSessionConf <- Synchronized.make(mutable.Map(sessionConf.toList: _*))
db = sessionConf.getOrElse("DBNAME", Database.DEFAULT_DATABASE)
defaultSchema <- Ref.make(AtomicReference(db))
_ <- accountAuthenticator.auth(username, password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.bitlap.server.session

import java.util.Vector as JVector
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.*

import scala.collection.mutable
Expand All @@ -34,13 +32,14 @@ import com.google.protobuf.ByteString
import com.typesafe.scalalogging.StrictLogging

import zio.{ System as _, * }
import zio.Ref.Synchronized

/** Bitlap session implementation on a single machine
*/
final class SimpleLocalSession(
val getOperation: OperationHandle => Task[Operation],
val sessionHandle: SessionHandle = SessionHandle(HandleIdentifier()),
val sessionConfRef: Ref[mutable.Map[String, String]],
val sessionConfRef: Synchronized[mutable.Map[String, String]],
val sessionStateRef: Ref[AtomicBoolean],
val creationTimeRef: Ref[AtomicLong],
val lastAccessTimeRef: Ref[AtomicLong],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ package org.bitlap.server.session

import java.sql.*

import scala.collection.mutable.ListBuffer

import org.bitlap.common.BitlapLogging
import org.bitlap.common.exception._
import org.bitlap.core.*
import org.bitlap.core.sql.QueryExecution
import org.bitlap.network.enumeration.*
import org.bitlap.network.models.*
import org.bitlap.network.serde.BitlapSerde
import org.bitlap.server.config.BitlapConfigWrapper

import zio.*
Expand Down
Loading

0 comments on commit b06542b

Please sign in to comment.