Package com.oltpbenchmark.benchmarks.seats.util

Examples of com.oltpbenchmark.benchmarks.seats.util.FlightId


                    // Keep looping until we get a FlightId that we haven't seen yet for this date
                    while (true) {
                        this.populate(date);
                       
                        // Generate a composite FlightId
                        this.flight_id = new FlightId(this.airline_id,
                                                      profile.getAirportId(this.depart_airport),
                                                      profile.getAirportId(this.arrive_airport),
                                                      this.start_date, this.depart_time);
                        if (this.todays_flights.contains(this.flight_id) == false) break;
                    } // WHILE
View Full Code Here


                    value = ((CustomerId)this.current[0]).encode();
                    break;
                }
                // FLIGHT ID
                case (2): {
                    FlightId flight_id = (FlightId)this.current[1];
                    value = flight_id.encode();
                    if (profile.getReservationUpcomingOffset() == null &&
                        flight_id.isUpcoming(profile.getFlightStartDate(), profile.getFlightPastDays())) {
                        profile.setReservationUpcomingOffset(id);
                    }
                    break;
                }
                // SEAT
View Full Code Here

    private final void loadCachedFlights(ResultSet vt) throws SQLException {
        int limit=1;
        while (vt.next() && limit++<SEATSConstants.CACHE_LIMIT_FLIGHT_IDS) {
            int col = 1;
            long f_id = vt.getLong(col++);
            FlightId flight_id = new FlightId(f_id);
            this.cached_flight_ids.add(flight_id);
        } // WHILE
        if (LOG.isDebugEnabled())
            LOG.debug(String.format("Loaded %d cached FlightIds", this.cached_flight_ids.size()));
    }
View Full Code Here

    public FlightId getRandomFlightId() {
        assert(this.cached_flight_ids.isEmpty() == false);
        if (LOG.isTraceEnabled())
            LOG.trace("Attempting to get a random FlightId");
        int idx = rng.nextInt(this.cached_flight_ids.size());
        FlightId flight_id = this.cached_flight_ids.get(idx);
        if (LOG.isTraceEnabled())
            LOG.trace("Got random " + flight_id);
        return (flight_id);
    }
View Full Code Here

            stop_date = new Timestamp(start_date.getTime() + (SEATSConstants.MILLISECONDS_PER_DAY * 2));
        }
       
        // Use an existing flight so that we guaranteed to get back results
        else {
            FlightId flight_id = this.profile.getRandomFlightId();
            depart_airport_id = flight_id.getDepartAirportId();
            arrive_airport_id = flight_id.getArriveAirportId();
           
            Timestamp flightDate = flight_id.getDepartDate(this.profile.getFlightStartDate());
            long range = Math.round(SEATSConstants.MILLISECONDS_PER_DAY * 0.5);
            start_date = new Timestamp(flightDate.getTime() - range);
            stop_date = new Timestamp(flightDate.getTime() + range);
           
            if (LOG.isDebugEnabled())
                LOG.debug(String.format("Using %s as look up in %s: %d / %s",
                                        flight_id, proc, flight_id.encode(), flightDate));
        }
       
        // If distance is greater than zero, then we will also get flights from nearby airports
        long distance = -1;
        if (rng.nextInt(100) < SEATSConstants.PROB_FIND_FLIGHTS_NEARBY_AIRPORT) {
            distance = SEATSConstants.DISTANCES[rng.nextInt(SEATSConstants.DISTANCES.length)];
        }
       
        if (LOG.isTraceEnabled()) LOG.trace("Calling " + proc);
        List<Object[]> results = proc.run(conn,
                                          depart_airport_id,
                                          arrive_airport_id,
                                          start_date,
                                          stop_date,
                                          distance);
        conn.commit();
       
        if (results.size() > 1) {
            // Convert the data into a FlightIds that other transactions can use
            int ctr = 0;
            for (Object row[] : results) {
                FlightId flight_id = new FlightId((Long)row[0]);
                assert(flight_id != null);
                boolean added = profile.addFlightId(flight_id);
                if (added) ctr++;
            } // WHILE
            if (LOG.isDebugEnabled()) LOG.debug(String.format("Added %d out of %d FlightIds to local cache",
View Full Code Here

    /**
     * Execute the FindOpenSeat procedure
     * @throws SQLException
     */
    private boolean executeFindOpenSeats(FindOpenSeats proc) throws SQLException {
        final FlightId search_flight = this.profile.getRandomFlightId();
        assert(search_flight != null);
        Long airport_depart_id = search_flight.getDepartAirportId();
       
        if (LOG.isTraceEnabled()) LOG.trace("Calling " + proc);
        Object[][] results = proc.run(conn, search_flight.encode());
        conn.commit();
       
        int rowCount = results.length;
        assert (rowCount <= SEATSConstants.FLIGHTS_NUM_SEATS) :
            String.format("Unexpected %d open seats returned for %s", rowCount, search_flight);
   
        // there is some tiny probability of an empty flight .. maybe 1/(20**150)
        // if you hit this assert (with valid code), play the lottery!
        if (rowCount == 0) return (true);

        LinkedList<Reservation> cache = CACHE_RESERVATIONS.get(CacheType.PENDING_INSERTS);
        assert(cache != null) : "Unexpected " + CacheType.PENDING_INSERTS;
       
        // Store pending reservations in our queue for a later transaction           
        BitSet seats = getSeatsBitSet(search_flight);
        tmp_reservations.clear();
       
        for (Object row[] : results) {
            if (row == null) continue; //  || rng.nextInt(100) < 75) continue; // HACK
            Integer seatnum = (Integer)row[1];
         
            // We first try to get a CustomerId based at this departure airport
            if (LOG.isTraceEnabled())
                LOG.trace("Looking for a random customer to fly on " + search_flight);
            CustomerId customer_id = profile.getRandomCustomerId(airport_depart_id);
         
            // We will go for a random one if:
            //  (1) The Customer is already booked on this Flight
            //  (2) We already made a new Reservation just now for this Customer
            int tries = SEATSConstants.FLIGHTS_NUM_SEATS;
            while (tries-- > 0 && (customer_id == null)) { //  || isCustomerBookedOnFlight(customer_id, flight_id))) {
                customer_id = profile.getRandomCustomerId();
                if (LOG.isTraceEnabled())
                    LOG.trace("RANDOM CUSTOMER: " + customer_id);
            } // WHILE
            assert(customer_id != null) :
                String.format("Failed to find a unique Customer to reserve for seat #%d on %s", seatnum, search_flight);
   
            Reservation r = new Reservation(profile.getNextReservationId(getId()),
                                            search_flight,
                                            customer_id,
                                            seatnum.intValue());
            seats.set(seatnum);
            tmp_reservations.add(r);
            if (LOG.isTraceEnabled())
                LOG.trace("QUEUED INSERT: " + search_flight + " / " + search_flight.encode() + " -> " + customer_id);
        } // WHILE
     
        if (tmp_reservations.isEmpty() == false) {
            Collections.shuffle(tmp_reservations);
            cache.addAll(tmp_reservations);
View Full Code Here

TOP

Related Classes of com.oltpbenchmark.benchmarks.seats.util.FlightId

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.